[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Scheme-reports] Two Informal Comments on r7rs Small, draft 9



Jay Sulzberger scripsit:

> I think the two meanings of "begin" are so different that each should
> have its own name.

I fear that boat sailed back in Maclisp days, if not earlier: progn,
the ancestor of begin, served both functions even back then.  Too much
depends on it to change it now.

> And what, there is yet a third meaning for "begin", when used in a
> library declaration?

Yes.  Syntactically it's like the splicing begin, but it doesn't
actually splice, there being no outer context of code or declarations
to splice into.  We could have done that otherwise, used `block` or
`code` or `body` instead, but we went with `begin`, just as we went with
`include` instead of `file` or the like.  The language of libraries is
really a small DSL, not Scheme, but we chose to recycle the identifiers
of Scheme as much as possible.

> But whether there is a difference in behavior is not clear to me,
> because of this behavior of the top-level: things get evaluated in
> order of typing and displayed on the screen in the same order.  So,
> at top level, the last thing in the "splice" expression will just be
> evaluated and displayed, just the same as if wrapped if the "splice"
> were a proper "begin".

Not necessarily.  Syntactic `begin`, which is valid wherever an
expression is valid, accepts only expressions, evaluates them in order,
discards the values of all but the last, and returns the value(s) of
the last as its value(s).  Splicing `begin`, which is only valid in
top-level-ish contexts, allows both expressions and definitions, and
just disappears.  So you can type

(begin (define x 32) (define y 33))

into your REPL and get whatever your implementation outputs for a
definition of x followed by a definition of y -- often nothing, but not
always, as in MIT Scheme.

> OK, now I think I get why "splice" and the "begin" that returns a
> value might be notationally conflated: Because all <body>'s in r7rs
> small, draft 9, include an implicit "begin" at the start of the list
> of things which make up the body.

Actually they don't.  If they did, internal definitions wouldn't be
allowed there, but they are.  If anything is implicit, it's a `let` that
doesn't bind any variables, since that does allow internal definitions,
but it does so by virtue of having a <body>, and explaining bodies by
bodies is a vicious circle.  Best to just say some constructs allow a
<body> and others (like `cond`) don't.

-- 
We are lost, lost.  No name, no business, no Precious, nothing.  Only empty.
Only hungry: yes, we are hungry.  A few little fishes, nassty bony little
fishes, for a poor creature, and they say death.  So wise they are; so just,
so very just.  --Gollum        cowan@x  http://ccil.org/~cowan

_______________________________________________
Scheme-reports mailing list
Scheme-reports@x
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports