3

I save the variable value (setf num (+ 4 5)) like this and I save the (setf str '("Hello")).

And then I want make a list like this (setq v '(num str)). However because of the single quote, it doesn't recognize it as a string and not working as expected.

how can i make a list with variable value?

sds
  • 58,617
  • 29
  • 161
  • 278
MinSeob Lim
  • 101
  • 1
  • 3
  • 9
  • Use [`list`](http://clhs.lisp.se/Body/f_list_.htm) or [`cons`](http://www.lispworks.com/documentation/lw70/CLHS/Body/f_cons.htm) – Sylwester Feb 06 '17 at 15:23
  • (list num str) or cons it doesn't work .. how to use this function? – MinSeob Lim Feb 06 '17 at 15:29
  • `(list var1 var2)` is the same as `(cons var1 (cons var2 '()))`. What doesn't work? – Sylwester Feb 06 '17 at 15:32
  • I'm sorry to ask you further. but one more i want to ask question. i making this function. (f 3 4) (sum = 7) (f 'a 'b) (not num!) i try to (format nil "sum = ~D." x) but, my problem is how can i make use formatting in list? – MinSeob Lim Feb 06 '17 at 15:47
  • You can just quote the elements you want to be literal: `(list 'sim '= 7)`. IN place of 7 you can just put a variable or an expression. – Sylwester Feb 06 '17 at 15:56
  • Thank you . It was solved because of you. – MinSeob Lim Feb 06 '17 at 16:22
  • Possible duplicate of [When to use 'quote in Lisp](http://stackoverflow.com/questions/134887/when-to-use-quote-in-lisp) – sds Feb 24 '17 at 15:01

1 Answers1

4

The special operator quote prevents evaluation of your variables.

You need to call a function (which evaluates its arguments), e.g., list:

(list num str)
==> (9 "Hello")
sds
  • 58,617
  • 29
  • 161
  • 278