[parenscript-devel] BLOCK/RETURN-FROM

Red Daly reddaly at gmail.com
Tue Jun 7 19:24:23 UTC 2011


Generally, the idea is to implement a runtime function called SIGNAL in
Parenscript and use JS's try/catch to work with the stack.

Remember that handler-bind handlers are executed before the stack is unwound
in an exceptional situation, while handler-case handlers are executed when
already unwound.  SIGNAL checks the available handlers and restarts.  If a
handler is found that accepts the error SIGNAL returns whatever that handler
wants to return.  Otherwise it throws a particular type of object (one with
a property named 'ps-signal-p).  HANDLER-CASE expands into a try-catch block
where the catch inspects anything thrown for a 'ps-signal-p property and
treats only such thrown objects as signals to be intercepted.

That's the general idea.  See
https://github.com/gonzojive/paren-psos/blob/master/src/conditions-macrology.lispand
https://github.com/gonzojive/paren-psos/blob/master/src/paren/paren-conditions.paren

Since conditions rest upon the type system, this is integrated with PSOS,
the Parenscript version of CLOS.

- Red

On Wed, Jun 8, 2011 at 1:51 AM, Daniel Gackle <danielgackle at gmail.com>wrote:

> Red,
>
> While we're sort of on the topic... I recall that Vladimir liked your
> implementation of conditions in PS quite a bit. If you have a minute, would
> you care to summarize the basic idea? Alternatively I could just not be lazy
> and go look at it :)
>
> Daniel
>
>
> On Tue, Jun 7, 2011 at 12:07 PM, Red Daly <reddaly at gmail.com> wrote:
>
>> At one point I had this implemented using try-catch unless Parenscript's
>> compiler could prove (rather naively) that the return-from clause was always
>> executed.  I am usually way behind the official branch, and I'm not sure if
>> my changes ever made it in, and if they did if this case is a bug.  Anyway
>> it would do something like
>>
>> function foo() {
>>    try {
>>    var bar = function () {
>>        throw { 'ps-return-foo341' : 42 };
>>    };
>>     bar(); }
>>    catch (e) {
>>       if ('ps-return-foo341' in e)
>>          return e['ps-return-foo341'];
>>       else
>>            throw e;
>> };
>>
>> verbose, but it should always work.  other try-catch tricks allow
>> lisp-style conditions, which I detailed in a post in this list within the
>> year.  in case of group interest the relevant code is available at
>> https://github.com/gonzojive/paren-psos and
>> https://github.com/gonzojive/parenscript
>>
>> Viva Parenscript!
>>
>> Red
>>
>>
>> On Tue, Jun 7, 2011 at 11:40 PM, <sblist at me.com> wrote:
>>
>>> Hi,
>>>
>>> I was wondering if the BLOCK/RETURN-FROM feature in PS intends
>>> to support the following case:
>>>
>>> (ps (defun foo ()
>>>          (flet ((bar () (return-from foo 42)))
>>>            (bar))))
>>>
>>> =>
>>>
>>> WARNING: Returning from unknown block FOO
>>> "function foo() {
>>>    var bar = function () {
>>>        return 42;
>>>    };
>>>    return bar();
>>> };"
>>>
>>> In order to try and get around the warning, I tried this:
>>>
>>> (ps (defun baz ()
>>>          (block foo
>>>            (flet ((bar () (return-from foo 42)))
>>>              (bar)))))
>>>
>>> =>
>>>
>>> WARNING: Returning from unknown block FOO
>>> "function baz() {
>>>    var bar = function () {
>>>        return 42;
>>>    };
>>>    return bar();
>>> };"
>>>
>>> but that didn't seem to work. Any ideas on how to achieve lexical
>>> return here?
>>>
>>>        - Scott
>>>
>>>
>>> _______________________________________________
>>> parenscript-devel mailing list
>>> parenscript-devel at common-lisp.net
>>> http://lists.common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel
>>>
>>
>>
>> _______________________________________________
>> parenscript-devel mailing list
>> parenscript-devel at common-lisp.net
>> http://lists.common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel
>>
>>
>
> _______________________________________________
> parenscript-devel mailing list
> parenscript-devel at common-lisp.net
> http://lists.common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/parenscript-devel/attachments/20110608/8af43db1/attachment.html>


More information about the parenscript-devel mailing list