Search code examples
lispmetalanguage

How do I put the code `cons[A;B]` in a repl, run it, and see the output `(A . B)`?


I found a LISP 1.5 Manual with some code in it.

This one is from Section 1.2

Examples

    cons[A;B]=(A . B)

From reading through the manual it looks like the function cons is taking two atoms as input arguments, A and B, and outputting an S-expression, (A . B).

Question:

How do I put the code cons[A;B] in a repl, run it, and see the output (A . B)?

I'm expecting to do something like:

~ $ lisp1.5
> cons[A;B]
=> (A . B)

For example, if I went to https://www.ruby-lang.org/en/ and saw some code, I would copy it, type irb into my shell and paste it.

enter image description here

~ $ irb
irb(main):001:0> puts "Hello World!"
Hello World!
=> nil

Solution

  • Section 1.2 of the manual explains that this is only a notation, used to help readers distinguish between functions and S-expressions (emphasis mine).

    We shall introduce some elementary functions of S-expressions. To distinguish the functions from the S-expressions themselves, we shall write function names in I lower case letters, since atomic symbols consist of only upper case letters. Furthermore, the arguments of functions will be grouped in square brackets rather than parentheses. As a separator or punctuation mark we shall use the semicolon.

    It is followed by an example:

    cons[A ; B] = (A . B)
    

    The manual introduces Lisp, its evaluation model, the compiler, etc. The above is the mathematical definition of cons, where A and B are metavariables: for all values A and B, the application of cons on A and B is a cons-cell where the CAR part is A and the CDR part B. If someone developed a denotational semantics to express Ruby's evaluation model, you would have the same kind of definitions. You can convert this notation if you want, i.e. you write (cons 1 2) to test it concretely. But the 1.5 manual is arguably not the best starting point for learning Common Lisp, as standardized since 1994. You could try the following ones, instead:

    Please consult Cliki, the Common Lisp wiki.