0

I'm trying to understand the view that procedures and data are virtually the same in lisp. SICP says that:

  • the values of numerals are the numbers that they name,
  • the values of built-in operators are the machine instruction sequences that carry out the corresponding operations, and
  • the values of other names are the objects associated with those names in the environment.

The second stipulation says that "the values of built-in operators are the machine instruction sequences that carry out the corresponding operations." if I wish to change the values thereby changing the machine instructions, like this:

  (define + 2)

  (* + 3) ;6

it works fine.

Now, the first case stipulates that "the values of numerals are the numbers that they name". If I type

  2

The value is the representation of 2 that gets outputted. Now, if I wish to change it, like this:

  (define 2 +) ;bad syntax

Why is that?

lightning_missile
  • 2,821
  • 5
  • 30
  • 58

2 Answers2

2

In any definition of a language, you need a distinction between symbols (if you have symbols) or names, and literals (in languages which only have literals, some of which code for instructions, this is not necessary.)

In the lisp in your example, 2 and 3.1415 are literals - + may be a symbol. Thus, it makes sense that you can re-assign a symbol, or name, to point somewhere else. Literals, however, will always be data. They are distinct from names.

You could define a language where literals are, just like +, symbols mapped to a default value, able to be re-mapped if you wish. An example of such a language might be the C pre-processor.

EDIT: More generally, you comment was about how "code is data" in lisp. Your example is a bad example of this feature - it is a question which concerns the parser or grammar of the language and its tokens.

A better example would be the following:

(+ 2 3)

This expression is both an executable statement, and a data structure. Namely it can code for "a function invocation which returns 5" or, if prefixed by a "do not evaluate me straight away '" the pair structure

(+ . (2 . (3 . NIL)))

which is the standard linked list structure found in lisp implementations. You can pass this data structure around in code, execute it later with something like the EVAL function, or (most powerfully), edit it so that it does something else and then execute it.

This is possible because lisps are homoiconic - the source code works both as code and data.

tehwalrus
  • 2,589
  • 5
  • 26
  • 33
2

procedures and data are virtually the same in lisp

That's not the case. Procedures are data. One kind of data. There are other kinds of data: numbers, strings, cons cells, symbols, vectors, ...

In a Scheme program, a symbol is a variable. You can modify the binding between the variable and a value. That's why you might be able to change the binding of the variable +.

But it is not possible to change 2, since it is a number and not a variable. A number has no binding. The value of 2 is already 2.

Rainer Joswig
  • 136,269
  • 10
  • 221
  • 346
  • Then can you explain further on what the statement "the values of numerals are the numbers that they name" mean? I got really confused by this because I thought "numbers that they name" talks about the representation of numbers at the loer levels. – lightning_missile Oct 17 '16 at 12:37
  • 1
    @morbidCode, the same *number* can be written in different ways through different *numerals*. For instance the number represented by 2 in decimal notation can be represented also by the numeral 10 in binary notation. Both represent the same number, which is an abstract entity. When we speak informally, or when there is no ambiguity, we can say that 2 is a number, but in programming languages you could use different numeral systems, for instance in many languages both the numerals #x03BB and 955 denote the same number. – Renzo Oct 17 '16 at 13:11
  • @Renzo got it. But what does this mean when we say "value" in this context? Specifically "the values of numerals" and "The value of 2 is already 2." 2 is itself a value right? How can I distinguish between the name and the value? – lightning_missile Oct 17 '16 at 13:28
  • 1
    @morbidCode, in a program you write numerals (for instance series of decimal digits, or hexadecimal digits), and when the program is executed they are converted into values, i.e. objects inside the computer memory .(that are again a concrete, physical, representation of the numbers) – Renzo Oct 17 '16 at 13:46