Extend assoc and dissoc to work on namespaces
Since namespaces are so very similar to maps, it seems useful to have assoc and dissoc work on namespaces as well, with the obvious semantics.
Incidentally, assoc works on strings, although that is not documented:
⬥ assoc abc 1 x
⮕ axc
@hanche: Do you have a real world use case for treating namespaces in the manner you propose? It's probably justified if only for orthogonality with other objects handled by those two commands. But it's easier to justify such a change if there is an actual use case. Especially since there are likely to be unexpected side-effects of such a change.
My primary use case, for now, is to help build a namespace to feed to eval. I'd like to write this (simplified – code for &on-end condition omitted):
fn . {|&ns=(ns [&]) file @args|
eval (slurp <$file) &ns=(assoc $ns args $args)
}
My current code converts the given namespace to a map, adds the args item to it, and converts the result back to a namespace once more. I would have liked to avoid that.