Tobias Brandt <[email protected]> writes: > I don't really care what (lambda ()) evaluates to as long as it's > consistent with the rest of the language. But what rubs me the wrong > way is that > > (define x (begin)) > (lambda () x) > > is not the same as > > (lambda () (begin)) > > because one of the strength of functional programming is referential > transparency. Therefore I would expect the definition of x (which has > no side effects) to be substitutable for x itself. This is apparently > not the case as one (begin) has a different meaning than the other > because of its context.
I agree it's annoying. However it only breaches referential transparency on a superficial, textual level, or not at all depending on your definition. In your example, the right-hand side of the `define' is (grammatically) an <expression> whereas the other form is in a <body> position, so it's not so that you're exchanging two <expression>s. It's rather so that a valid <expression> (in Guile Scheme at least, see below) happens to also be a valid <body> (which however leads to an error later on). By the way, it comes out the expression-begin is actually specified (in R5 through 7RS) to take at least one operand, so in your example the (define x (begin)) is unspecified in first place. OTOH, a <body> is defined as "<definition>* <sequence>", where <sequence> is "<command>* <expression>", meaning that in a <body> that is just "(begin)", the (begin) is an <expression>. In RnRS, (begin) is actually an invalid <expression>, but since Guile allows it in general, one would expect it to work here too. (Guile's "excuse" here could be that it uses a wholely different grammar that is compatible with the RnRS one, instead of one constructed through incremental extensions to it.) I now wish Guile simply didn't allow (begin) as a valid expression. :-) While this is just a nitpick, I'll file a bug report for it. > As another data point, this seems to be fine: > > (use-modules (oop goops)) > (define-method (foo)) > > So, GOOPS doesn't mind empty method bodies. However > > (define-method (foo) (begin)) > > fails. Not very consistent either, I'm afraid. I just checked and `define-method' (deferring to the auxilliary macro `method') special-cases zero-form method bodies, simply giving them a body of (if #f #f), so it introduces the asymmetry intentionally. Dunno why, but changing it could break backwards compatibility. OTOH it's nasty that the second failes when the first doesn't, so I'll file an additional report for that. > Cheers, > Tobias Taylan
