tags:

views:

347

answers:

2

As the Wikipedia article explains, begin in Scheme is a library form that can be rewritten using more fundamental forms like lambda.

But how do you rewrite a begin, especially considering the following?

x
===> error: undefined identifier: x
(begin (define x 28) x)
===> 28
x
===> 28
+4  A: 

You cannot. The thing is that begin has two roles: one is sequence a bunch of side-effectful expressions, and the other is that it is used to "splice" macro results. The fact that you can use begin with a definition as in the above is a result of this second feature, and you cannot write it yourself.

Eli Barzilay
Then why is it considered a"library syntax", and not simply "syntax" in R5RS? I thought you could rewrite library forms using fundamental forms only?
eljenso
That's a mistake (together with the wikipedia article).
Eli Barzilay
[citation needed]
Javier
No, a citation is not needed -- a counter example is sufficient. eljenso's example *is* such a counter example.
Eli Barzilay
+1  A: 

You are still welcome to try writing a version of begin which satisfies its first role: sequencing.

(define-syntax sequencing
  (syntax-rules ()
    [(_ expression) expression]
    [(_ expression expressions ...)
     ((lambda (ignored) (sequencing expressions ...)) expression)]))

Here is the post from which I took that snippet. It provides better context if you are interested, and you might be.

grettke