0

Given a list of things, I want to create an alist by applying a function which creates elements of the alist.

For example, what is the implementation of doit here:

(doit '("a" "b" "c"))
;; => (("a" . "A") ("b" . "B") ("c" . "C"))
2
  • You should be more specific in your questions. The answer you accepted does not exactly answer your question. Mine, yes.
    – gigiair
    Apr 16 at 21:39
  • Thank you for feedback @gigiair. But My question is how to to create an alist. The example with the doit function was just an example to make my question more clear. The answer from @jagrg is just perfect. It captures the essence of the problem here.
    – Witek
    Apr 17 at 8:55

2 Answers 2

2

mapcar is another option:

(mapcar (lambda (x)
          (cons x (upcase x)))
        '("a" "b" "c"))
1

It can be

(defun doit (l)
  (seq-map (lambda (x)
             (cons x (upcase x))) l))
3
  • What is the advantage of using seq-map over mapcar? ( seq-map defined in seq.el.gz seems to be only a wrapper to mapcar)
    – Claudio
    Apr 16 at 22:49
  • 1
    seq-map operates on sequences of any type.. It is not just a wrapper.
    – gigiair
    Apr 17 at 5:32
  • @Claudio: deleted
    – shynur
    Apr 17 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.