4

I was reading this paper on LISP by McCarthy (way above my skill set). While defining the evaluation of (LABEL, f, e) here, he used an M-expression (I think it's an M-expression, correct me if I am wrong) list[x;y]. {Actually, list[cadar[e];car[e]]}.

According to how I understood it, it symbolizes (e1, e2) where e1 and e2 are S-expressions. Did I get it right or is it something else, and what is the corresponding expression for list[x;y]?

Thank you.

volf
  • 83
  • 1
  • 10

1 Answers1

3

In the metalanguage, the expression list[a; b] denotes the application of the function list to two arguments, which builds a list with two elements, which are the result of the evaluation of a and b respectively.

In the language of the S-expressions, so, this would be written as the usual function call: (LIST a b), that is a list with the first element the name of the function (LIST) and the rest of the elements the actual parameters of the function. Note that here I use the notation (a b) for S-expressions, and not (a, b). McCarthy itself changed this notation later, and in the LISP 1.5 Programmer’s Manual. 2. ed. Cambridge, Mass: MIT Pr, 1979. the new notation is used.

Renzo
  • 26,848
  • 5
  • 49
  • 61
  • What would be then the difference between `cons[x ; y]` and `list[x ; y]` then? Is it that in `list[x ; y]` , `x` and `y` stand for atoms? – volf Jan 10 '18 at 02:15
  • 2
    @Geek, `x` and `y` stands for generic (meta-)expressions which evaluates to data (for instance atoms, conses, numbers, etc., in other words, S-expressions). `List` differs from `cons` since a cons is a pair of two S-expressions, while a list of 1 element is a cons of the element with NIL, a list of 2 elements is a cons of the first element with the cons of the second with NIL, etc. See pages 36-37 of [Lisp 1.5 Programming Manual](http://www.softwarepreservation.org/projects/LISP/book/LISP%201.5%20Programmers%20Manual.pdf), in which the first part is a rewriting of the article that you cited. – Renzo Jan 10 '18 at 07:27
  • 4
    @Geek `(cons x y)` constructs a cell whose `car` is the value of `x` and whose `cdr` is the value of `y`. For instance `(cons 1 2)` makes `(1 . 2)`. By contrast, `(list 1 2)` makes `(1 2)`, an object which contains two cons cells, equivalent to `(1 . (2 . nil))`. The expression `(list x y)` produces the same result as `(cons x (cons y nil))`. The `list` function has to iterate over the arguments and allocate cells to them (perhaps by calling `cons`, one time for each argument), putting those together into a `nil`-terminated list which is returned. – Kaz Jan 13 '18 at 02:48