Post by Axel Reichert
P. S.: Does anyone know about the motivation/history behind the
different bracketing of "define" and "defun" above?
Note that Scheme, being a Lisp-1, originally just had this:
(define symbol (lambda (...) ...))
This syntax is still there in Scheme, of course: it's just
the syntax for defining a variable.
The (define (function arg ...)) syntax got overloaded onto this
using the same define symbol.
It more or less has to have the variation in list structure to
disambiguate the two variants, or at least to do so in what is probably
the simplest way with the fewest parsing hacks.
Note that (define function (arg)) looks indistinguishable from
the function being defined to have the value of evaluating the
(arg) expression. We could have some hacky rule like that the
body must not be empty:
(define function (arg) something-here)
but that's annoying, possibly error prone, and possibly interferes
future docstring support (or possibly current docstring support
in some Scheme implementations that have it as an extension)
That is to say, if something-here is a string
(define function (arg) "blah")
that could in some implementations be taken as a docstring for the
variable foo whose value is obtained by evaluating (arg), which prevents
us from using this syntax to write a function which returns a literal
So then we need a rule like:
(define function (arg) [ optional-docstring ] something-here)
It starts to get messy and ugly, compared to the alternative
which was selected, which requires define to just look at whether
its argument is a list or an atom.
Also, Scheme is inspired by the C (for instance, just look at the
unspecified order of argument evaluation, and undefined return value
of side-effecting procedures). So this can be regarded as an expression
of admiration for C's "declaration follows use" syntax design principle.
TXR Programming Lanuage: http://nongnu.org/txr
Music DIY Mailing List: http://www.kylheku.com/diy
ADA MP-1 Mailing List: http://www.kylheku.com/mp1