Justin Smith <
noise...@gmail.com> writes:
Hi Justin & Hans-Peter,
> Typically in clojure we use hash-maps (represented literally as {})
> where other lisps would use an alist.
One difference between alists and maps is that in alists a "key" can
occur multiple times, and then the first entry with that key shadows all
following entries with that key (with respect to retrieval with
`assoc`).
Well, that feature is probably not used very often, but if you can't
rule out its usage, you also can't convert alists to maps and expect
they're equivalent.
> Regarding reading assoc list literals, I wouldn't be surprised if
> someone had written this function already, but I doubt it is in the
> core language.
This should do the trick:
(defn alist-assoc [key alist]
(first (filter #(= key (first %)) alist)))
And to add a list to an alist one would use `cons` in Clojure just like
one would use `cons` in CL, Scheme, or Elisp, too.
Bye,
Tassilo