3

This question already has an answer here:

So as far as I understand it you create association lists that look like

'((rose . red)
 (violet . violet)
 (chrysanthemum . who-knows))

My question is, what do you do if you want rose, violet, etc., to be evaluated before they're put into the alist?

For example, for normal lists you can do

(list 1 2 3 4)

instead of

'(1 2 3 4)

How do you replicate this functionality? I'm new to elisp and Emacs, so please forgive any errors or misnomers.

marked as duplicate by Drew, npostavs, wvxvw, Luke, Mark Karpov Aug 23 '15 at 13:38

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

Here you go:

(list (cons rose red)
      (cons violet violet)
      (cons chrysanthemum who-knows))

each flower should be bound to a value.

2

An alist is just a list. So, you can use all the normal list-constructing functions like cons or list. Or, if you want to write one that looks like a constant, you can use backquote:

`((,(rose) . red)
  (,(violet) . violet))

This will evaluate rose and violet at construction time and substitute the results.

  • Or if rose is a variable: ,rose. – Drew Aug 23 '15 at 2:06