[parenscript-devel] Implicit return for function bodies

sblist at me.com sblist at me.com
Sun Nov 29 21:10:33 UTC 2009


Hi Vladimir,

On 2009-11-27, at 5:24 PM, Vladimir Sedach wrote:

> Just pushed patches that fix RETURNing of cond and symbol-macrolet.
> Let me know if you catch anything else amiss.
> 
> Thank you,
> Vladimir
> 
> 2009/11/23  <sblist at me.com>:
>> On 2009-11-05, at 12:20 PM, sblist at me.com wrote:
>> ...
>> 
>> This is still the case as of the latest commit, so
>> code like this fails:
>> 
>> (ps (lambda ()
>>      (cond ((foo? x) (loop for y in x do (foo y)))
>>            ((bar? x) x)
>>            (t t))))

This form now emits valid JS. However, using DOLIST instead
of LOOP here causes a syntax error:

(ps (lambda ()                                                         
      (cond ((foo? x) (dolist (y x) (foo y)))                          
            ((bar? x) x)                                               
            (t t))))
=>
"function () {                                                                   
    if (foowhat(x)) {                                                            
        return for (var y = null, _js_idx1288 = 0; _js_idx1288 < x.length; _js_i\
dx1288 += 1) {                                                                   
            y = x[_js_idx1288];                                                  
            foo(y);                                                              
        };                                                                       
    } else if (barwhat(x)) {                                                     
        return x;                                                                
    } else {                                                                     
        return true;                                                             
    };                                                                           
};"

Here is some more curious DOLIST behavior:

SKYSHEET> (ps (lambda () (dolist (arg args) (foo arg))))
"function () {                                                                   
    for (var arg = null, _js_idx1289 = 0; _js_idx1289 < args.length; _js_idx1289\
 += 1) {                                                                         
        arg = args[_js_idx1289];                                                 
        foo(arg);                                                                
    };                                                                           
};"                                                                              
SKYSHEET> (ps (lambda () (let ((x y)) (dolist (arg args) (foo arg)))))
"function () {                                                                   
    var x = y;                                                                   
    return for (var arg = null, _js_idx1290 = 0; _js_idx1290 < args.length; _js_\
idx1290 += 1) {                                                                  
        arg = args[_js_idx1290];                                                 
        foo(arg);                                                                
    };                                                                           
};"

- Scott




More information about the parenscript-devel mailing list