2

I was wondering can we set a list from an already existing list?

(setq example1 '(1 2 3))
(setq example2 '((caddr example1) (cadr example1) (car example1)))

I know the way I've written it won't achieve the desired result but is there anyway to achieve that result?And how?

Thank you for your time!

Rainer Joswig
  • 136,269
  • 10
  • 221
  • 346
jakHunter
  • 305
  • 3
  • 13

1 Answers1

5

can we set a list from an already existing list?

Sure you can, but I think you are still confused about when quote should be used. Nothing inside a quoted expression is evaluated.

In order to set the list example2 with the elements of example1 would be enough to construct a list with that elements, such as:

(setq example2 (list (caddr example1) (cadr example1) (car example1)))
FrankS101
  • 2,112
  • 6
  • 26
  • 40
  • Thank you!I am new to lisp so yes I don't know when to use it i'm just playing around with stuff trying to get the hang of it so far I think I have got the hang of it of some the stuff.And can you recommend more documentation for stuff like this?Thanks again! – jakHunter Apr 01 '18 at 15:07
  • http://www.lispworks.com/documentation/common-lisp.html This is a good reference point. – FrankS101 Apr 01 '18 at 15:15
  • @jakHunter I would add to that the excellent Gigamonkeys book on Practical Common Lisp, which can be viewed for free online (http://www.gigamonkeys.com/book/). – Silvio Mayolo Apr 01 '18 at 15:16
  • Thanks but I already know those 2 sites aren't there any other? – jakHunter Apr 01 '18 at 17:41