Mark H Weaver <m...@netris.org> writes: > David Kastrup <d...@gnu.org> writes: > >>> You are suggesting that we wrap the expression within a (let () ...), >>> for the dubious benefit of allowing you to wrap the local forms in >>> (begin ...) instead of (let () ...). >> >> Are there even situations where you could put definitions after begin? >> How are they different from the situation where you can't? >> >>> I don't see any compelling benefit to this. On the other hand, I see >>> less elegant semantics and potential confusion among users, who might >>> reasonably expect the definitions in their (begin ...) to be added to >>> the implicit `letrec', as would happen if the (begin ...) were put in >>> place of (the-environment). >> >> begin can start with definitions, but not always? But (let () ...) can? >> >> Scheme is weird. > > `begin' is indeed quite weird in Scheme. Its meaning depends on the > context where it is found: > > * In expression context, it is like `progn' in Lisp. It evaluates the > expressions in order from left to right, and returns the value(s) of > the last expression. > > * At the top-level, or within an internal body where local definitions > are allowed (i.e. if every form above it in the internal body is a > definition), it is a _splicing_ operator: it acts as if the contents > of the begin were spliced into the surrounding context. This is > mainly for the benefit of macros, so that they may expand into > multiple definitions.
Well, what if begin were able to splice definitions into the original lexical context of the-environment? I think it would be strange if a continuation taken in that context would get to see new definitions. And if a continuation there does not get to see it, it would be strange if successive calls of local-eval on the same environment got to see it. So there is not much of a sensible option except an implicit (let () ...) wrapper for the sake of splicing begin, or bugging out for new definitions. In the light of local-eval evaluating a _form_ rather than a _body_ (stupid of me to forget), and seeing the weird semantics of begin, I agree that an implicit (let () ...) wrapper for a single form does not really appear to add significant gains. It would be marginally convenient and marginally confusing. So one might as well forget about it. -- David Kastrup