Consider the following s-expression:
((lambda (car) (car (quote (a b c)))) cdr)
In most scheme implementations I've tried, this evaluates to (b c)
because cdr
is passed to the lambda, which names it car
, taking precedence over the primitive implementation of car
.
The Little Schemer provides an implementation of scheme written in scheme in chapter 10. That implementation returns a
for the above expression, which seems incorrect to me.
It's clear why that implementation behaves that way: the names of primitive functions are treated as *const
rather than *identifier
here. A *const
which is not a number or boolean is rendered as a primitive and this is eventually hardwired to the actual primitives.
I believe that the correct implementation would be to have no special detection of primitive names, but rather to create an initial table in the value function that contains an entry mapping the primitive names to the actual primitive implementations.
My question is: is this a bug in The Little Schemer's implementation of scheme? Is this behaviour well specified in scheme, or was it maybe not well specified in 1974 when the book was written?