[parenscript-devel] Implicit RETURN for function bodies

Vladimir Sedach vsedach at gmail.com
Thu Aug 9 19:56:05 UTC 2007


I've though about this, but as you point out the expectation is that
the last s-exp in a defun body would have to compile to an expression,
otherwise existing code would break with very annoying and cryptic
error messages. The alternative is to examine whether the last s-exp
can be compiled to an expression or not (this is something that the
compiler refactoring I'm doing right now should make a little easier
to do), and if it can be, then wrap it in a return. However, this
could introduce unexpected surprises into the generated Javascript.
There is also the issue of how would you override this mechanism when
you explicitly want your function to return 'undefined'  and the last
statement just happens to be an expression. I think in this case, the
only clearly "right thing" to do is to stick with Javascript
semantics.

Vladimir

On 8/7/07, Red Daly <reddaly at gmail.com> wrote:
> Coming from Lisp, it is tiresome inserting return statements at the end of
> each function.  Should we change the behavior of Parenscript so that the
> last item in a function body is expected to be an expression and is
> returned?
>
> I am in favor of the change, though it may introduce incompatibility with
> existing code.
>
> An implementation:
> (defscriptmacro fn (lambda-list &body body)
>
>
>
> `(lambda ,lambda-list
>
>
>
>    ,@(butlast body)
>
>
>
>    (return ,(first (last body)))))
>
> Red
>
>
>
>
> _______________________________________________
> parenscript-devel mailing list
> parenscript-devel at common-lisp.net
> http://common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel
>
>



More information about the parenscript-devel mailing list