Block lambda exiting function during execurtion

François REMY fremycompany_pub at yahoo.fr
Fri Jan 13 04:27:41 PST 2012


I’ve a question about block lambda. What will be the output of the console for this code :

    
    let numbers=[1,2,3,4,5,6];
    let isPair=function(x) { 
        console.log(x); return (x&1)==0;
    }

    function getAnyWhere(elements, isValid) { 
        elements.forEach({(x) if(isValid(x)) return x; });
    }

    let fv = getAnyWhere(numbers, isPair);
    console.log(fv);

One could resume my question in three smaller ones :

(1) does the first 'block lambda return’ returns its value to fv directly.
(2) does the first ‘block lambda return’ aborts the forEach
(3) does the second ‘block lamdba return’ (if any) causes an error to be thrown
(4) does the execution of console.log(fv) continue in parallel with the following forEach iterations

To be useful, I think the behavior should be

(1) yes
(2) yes
(3) doesn’t happen; see 2.
(4) doesn’t happen; see 2.

However, it seems rather complex since the “forEeach” function could be any host function that was not mean to be aborted at any given time by callee.

If the response to (1) is no, I don’t see the point of ‘return’ returning from parent function. Did I miss something?
François
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120113/e3d99c5f/attachment.html>


More information about the es-discuss mailing list