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
On 8/7/07, Red Daly reddaly@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 prefer the core parenscript to be exactly equal to javascript with sexp syntax. I suggest another layer/language/something for Lisp-like additions like this. We have had a discussion about this before, one of my main points is that It makes it more easy to know what javascript is generated from your parenscript code.
The easiest thing is perhaps to add a prefix (for example the letter L) or postfix(for exampe a +) to forms that do magic stuff. So lambda+ and defun+ could have return values like this. I think the recent addition of optional and keyword parameteters (which by the way is a nice feature) should also go into a lambda+ function instead of the core parenscript.
Best wishes, Henrik Hjelte
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@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@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel
parenscript-devel@common-lisp.net