babellog

Tuesday, August 31, 2004

LISP - Help

I am trying get myself familiarize with LISP. I have the Little LISPer with me. Downloaded LispWorks personal edition. The problem is getting commands work :-) There is a command "car". The way I am issuing the command is

car ('x 'y 'z) in the prompt

and here is the stack trace

Error: Syntactic error in form ((QUOTE A) (QUOTE B) (QUOTE C)):
Illegal function name (QUOTE A).
1 (abort) Return to level 1.
2 Return to debug level 1.
3 Try evaluating ATOM again.
4 Specify a value to use this time instead of evaluating ATOM.
5 Specify a value to set ATOM to.
6 Return to level 0.
7 Return to top loop level 0.

Type :b for backtrace, :c

5 Comments:

  • At 9:59 PM, Blogger longdeparted said…

    sorry, I only have clisp here and it's been a while but this is what works.. You're (*giggle*) missing a few parentheses

    [1]> (car '(a b c) )
    A
    [2]> (car '(cow horse duck) )
    COW


    Does this help ?

     
  • At 8:43 AM, Blogger 88Pro said…

    Yes it does help. Thanks a loads :-)

     
  • At 11:20 AM, Blogger 88Pro said…

    I am going to put my understanding about atoms here. Please correct me if I am wrong.

    The single quote ' is used to specify an atom. So I could say 'cow. (a b c) is a list since it is atoms enclosed by brackets. But when you say '(a b c) what does that mean?

     
  • At 2:28 PM, Blogger longdeparted said…

    yikes. Having mentioned all the disclaimers about the blind leading the blind... ;)

    think of the quote operator as something that tells the Lisp interpreter that the symbol(s) following it will be a literal:
    'a = literal a
    '(b c d) = list of literals

    so, the short answer to your question is that the notation indicates that '(b c d) is a list of literals.

    Hmm, I'll give you another (slightly more complex) example using another function named "list". Run this and you should see why you got an error the first time

    Predict what result running the following will give:
    (car (list 'a '(b))))

     
  • At 3:34 PM, Blogger 88Pro said…

    I am more clear about atoms now. Thanks.

     

Post a Comment

<< Home