I’m trying to learn lisp and as i’m making my first steps i got stuck.
How can i get c element form following list: (a b (c.d))
I’ve tried: (caar (last '(a b (c.d)))) but it returns c.d and not only c
This however works if there are spaces between c, . , d ie: (caar (last '(a b (c . d))))
The problem i’m trying to resolves has the list specified without spaces. Can that be done or it’s a typo in the exercise?
Thanks.
LE: Uisng GNU Clisp http://clisp.cons.org/
Is it possible that the issue it’s caused by the implementation?
Your code is right, it’s a typo (or maybe a really bad font?) in the exercise.
In Lisp (Common Lisp and Scheme are the two I tested just now, I don’t know about Clojure), [nearly] the only divisions between symbols are spaces and parentheses. Even though . is used as literal syntax for
cons, if you type'(c.d), you get one symbol in a list, not two symbols in a cons cell.For example,
Edit: Since you are using Common Lisp, here is the list of relevant characters and the reader algorithm. To summarise,
(and)are terminating characters, while.is not. CLisp is performing according to the Common Lisp spec.