I know I can match and capture a key value pair in a K Map like so:
rule <k> UPDATE Key:Id Val:Int => .K ... </k>
<mycell> ... Key |-> Val ... </mycell>
<anothercell> X => X[Val <- 5] </anothercell>
But what if after the update in another cell I don’t need the Key anymore in mycell?
I know I can modify its value in the same rule, like so:
rule <k> UPDATE Key:Id Val:Int => .K ... </k>
<mycell> ... Key |-> ( Val => Dead) ... </mycell>
<anothercell> X => X[Val <- 5] </anothercell>
So now in other rules I can check if the key does not exist or maps to Dead, which is ugly because it doubles the number of rules. Another hack I found is to push a special instruction to the top of the k cell and add a second rule to remove the key like so:
rule <k> UPDATE Key:Id Val:Int => KILL Key ... </k>
<mycell> ... Key |-> Val ... </mycell>
<anothercell> X => X[Val <- 5] </anothercell>
rule <k> KILL Key => .K ... </k>
<mycell> M => M[Key <- undef] </mycell>
Which I don’t like because I need additional syntax for the deletion of keys and an additional rule.
What I would like to do is to match/capture a KV pair and remove the key all in one rule. I tried something like:
rule <k> UPDATE Key:Id Val:Int => .K ... </k>
<mycell> ... Key |-> ( Val => undef) ... </mycell>
<anothercell> X => X[Val <- 5] </anothercell>
But this does not work, to remove a key from a map I need a name for the map. Can this operation be done in K? If yes, what is the syntax for it?