According R6RS and R7RS (draft 6), lambda form must have at least one expression. So I guess this must be syntax error. (I could not find explicit sentence said raise an error, neither R6RS nor R7RS draft).
So, I checked some implementations, Gauche, Ypsilon, mosh, chibi-scheme, guile and Sagittarius.
The implementations raised syntax error: mosh, chibi-scheme, guile.
I guess these are strict for syntax.
Gauche returned a procedure which returns 0 or unspecified value, depending on how you defined.
Ypsilon returned a procedure which returns unspecified value.
The funniest behaviour was actually mine. It returned procedure which returns itself. This expression was valid;
(define (test)) (((test))) ;; #<closure test>But don't try this expression, it will abort with out of memory;
(((lambda ()))) ;; abort or never returnI guess this must be either syntax error or returning unspecified value.
Even (begin) returned closure.
The reason why it happened is because when calling a closure VM's ac register wasn't updated and if the next instruction is PUSH, yes, it just push the calling closure to the stack. I added one sentence to set unspecified value to ac register. Now it does not return weird closure by default. It was an interesting behaviour if it does not cause out of memory or infinite loop.
No comments:
Post a Comment