7

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.

2 Answers2

5

Here you go:

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

each flower should be bound to a value.

sds
  • 5,928
  • 20
  • 39
3

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.

Tom Tromey
  • 759
  • 4
  • 8