I have defined a function which takes a map. I thought to use destructuring to access the values. However, I also want to check whether there are any used keys.
So, for example something like…
(defun func1 [{:keys [a b c] :rest rest}]
(println a b c)
(println rest))
(func1 {:a 1 :b 2 :c 3 :d 4})
which would print
1 2 3
4
The reason that I want this is that if rest is not null, this is probably an error, which I’d like to signal. I know about :as, which I could use. But then I need to store the list of valid keys twice.
Am I missing something?
Phil
I don’t really understand why you’d ever want to know if there are things that you don’t care about anyways. If you’re trying to do something like “do something specific with these keys, and do something generic with the others” you could do something like:
If you are paranoid about having to mention the keywords twice, you can probably do something about that too, but I can’t imagine that it would be worth the bother.
If you’re that concerned about users passing in not exactly what you want, maybe a map isn’t the right data structure to use.