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?

7
  • Use list or cons Commented Feb 6, 2017 at 15:23
  • (list num str) or cons it doesn't work .. how to use this function? Commented Feb 6, 2017 at 15:29
  • (list var1 var2) is the same as (cons var1 (cons var2 '())). What doesn't work? Commented Feb 6, 2017 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? Commented Feb 6, 2017 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. Commented Feb 6, 2017 at 15:56

1 Answer 1

5

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")
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you. But could you please look at my comments on the above question?
You are welcome. You should ask a separate question for each issue instead of starting a comment conversation.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.