2
votes

I'm just starting out with LISP, as in, just opened the book, I'm two pages into it. I'm trying to understand what is and what is not an acceptable fn call. Every time I try to execute

(1 2 3 4)

I get an illegal fn call error same goes for

(cdr (1 2 3 4))
(first (1 2 3 4))
(a b c d)

Are CL programs unable to return lists? How would I go about using these functions or printing a list? I'm using the SLIME implementation if it matters. LISP is very different than anything I've worked with before and I want to be sure I'm getting it conceptually.

2
The only slime I've heard of for lisp is the emacs development environment, which can interact with several different implementations. It's probably worth you working out what implementation you're using. Also, in case you haven't found it, google "Common Lisp Hyperspec". - Marcin
I propose reading pages 3 and 4, too. - Rainer Joswig
haha, nice. I've read past it considerably, but the book is branching off and assuming that I've been able to execute the above code. The book doesn't say anything about using ' though... - hedgehogrider

2 Answers

5
votes

You need to quote lists if you are using them as constants. Otherwise, the system will try to call the function 1 on the arguments 2 3 4, which will not work (note that function calls have the same syntax as lists). Your examples should be:

'(1 2 3 4)
(cdr '(1 2 3 4))
(first '(1 2 3 4))
'(a b c d)
-1
votes

Hooo boy.

Look up Practical Common Lisp by Seibel. He's such a nice guy, he put it online for free reading. It's very useful.

Part of the definition of Lisp is this rule:

  • When a list is seen: Using the first element of the list, apply it to the rest of the list.

But wait: How do you actually enter lists then? There are two functions to do this: QUOTE and LIST.

As an example, let's print a list to the screen on standard out:

(format *standard-output* "~a" '(1 2 3 4))

For format, *standard-output* is aliased to t (well, at least in SBCL!), so usually we see (format t ....