[parenscript-devel] Patch: added JS label/break to PS

Daniel Gackle danielgackle at gmail.com
Fri Apr 9 06:38:07 UTC 2010

I just pushed a patch (authored by Scott) to implement JS's LABEL and BREAK
in PS. (Note that this patch deprecates LABELED-FOR since you can get the
same effect by combining LABEL and FOR. Was anybody using LABELED-FOR?)

Here's an example:

(label scope
    (when (bar)
      (break scope))


scope: {
    if (bar()) {
        break scope;

I was astonished to discover recently that JS has supported this ability all
along in the form of labeled statements and labeled breaks. I'd always
assumed that to get explicit returns from an arbitrary scope, you'd have to
resort to the ugly hack of muscling TRY/CATCH to do it, thinking that this
was the closest JS counterpart. (See
http://news.ycombinator.com/item?id=793092 for a thread in which several
people believe this.) But it appears we were all wrong.

What's not clear yet is how far this can be taken. Can you use it inside a
nested local function to return immediately from the top-level function?
That is one thing I've wanted for a long time.

In the ideal case, LABEL/BREAK could be used as a base for implementing a
proper BLOCK and RETURN-FROM in PS, something which we'd long believed to be
impossible. One challenge is that in CL, RETURN-FROM can take a value, which
becomes the value of BLOCK. In other words, BLOCK in CL is an expression
while LABEL in JS is not. It seems, though, that most of this challenge has
already been conquered with the development of implicit return in PS. The
only thing you'd need to add is detecting when BLOCK is being used as an
expression, declaring a gensymed variable and assigning whatever is
happening inside BLOCK to that variable (much like implicit return already
does with e.g. CASE), then put the variable in the expression position that
BLOCK was in. It seems like this ought to work. It would also make things
like this possible in PS:

(1+ (case foo
        (:eleven 11)
        (:twelve 12)))

Vladimir (and everybody), is the above clear? What do you think of it?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/parenscript-devel/attachments/20100409/03e4b5a2/attachment.html>

More information about the parenscript-devel mailing list