[parenscript-devel] Expressionize

Vladimir Sedach vsedach at gmail.com
Thu Aug 19 17:19:19 UTC 2010


> The 'expressionize' function seems to be at the core of implicit
> returns.  It seems to be a promising approach to morphing Javascript
> into an everything-is-an-expression language.

Yes. After I wrote implicit return it became obvious that could be
generalized into "expressionize."

> Unfortunately right now
> it is poorly documented and not used everywhere it could be.

I'm pretty sure it also has some pretty big bugs. More importantly, I
don't think it works as advertised if you try to use it in arbitrary
places right now.

> Hopefully we can discuss where this feature is heading publicly and
> finish up expressionizing parenscript.
>
> Right now LET does not seem to take advantage of expressionize the
> same way functions do.  LET fails to turn TRY into an expression,
> while implicit return works.  What would we need to do to add this?

At first thought all the places where the Parenscript special forms
need expressions are already annotated with the COMPILE-EXPRESSION
function. So one possible way is to just expressionize all statements
that end up getting compiled by COMPILE-EXPRESSION into lambdas that
get called in-place. This is what most other Lisp to JS compilers seem
to do. This would look like

(+ 1 (dolist ()...)) => (+ 1 (funcall (lambda () (var x) (dolist ()...
finally x = _) (return x)))

If we're willing to tolerate Scheme calling convention (argument
evaluation order is unspecified), this could be transformed into more
idiomatic JS:

(+ 1 (dolist () ...)) =>

(var x)
(dolist () ... finally x = _)
(+ 1 x)

I think I brought up this idea (undefined argument evaluation order)
before in relation to some other feature, but I can't find a mention
of that now.

Vladimir

> (ps:ps (let ((x (ps:try xxx
>                           (:catch (x) 5))))
>                  x))
> "var x233 = try {
>    xxx;
> } catch (x) {
>    5;
> };
> x233;"
>
>
> below works:
>
>> (ps:ps (lambda ()
>                  (ps:try xxx
>                          (:catch (x) 5))))
> "function () {
>    try {
>        return xxx;
>    } catch (x) {
>        return 5;
>    };
> };"
>
>
> Thanks for the insights,
> 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