Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

argument passing

14 views
Skip to first unread message

Norm Rubin

unread,
May 9, 2013, 8:01:36 AM5/9/13
to dev-tech-js-en...@lists.mozilla.org
I'm considering what sort of side effects an elemental function might have

Here are 3 ways to pass arguments to an elemental function


1) As arguments

P1.map (function (x,I,y) { use y[i] }, arg) - the entire array arg is available inside the elemental function

2) As exposed values
P2.map(function(x,i) { use arg[i]}) - the array arg is upward exposed and can be accessed inside the function

3) Via a closure

P3.map( {a:arg, f:function(x,i) { use a[i]}}.f) - the array is passed in as a hidden value



I can see why 1 and 3 are desirable, but 2 seems kind of problematic, would it be better to make this case an error?



-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information. Any unauthorized review, use, disclosure or distribution
is prohibited. If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------

Niko Matsakis

unread,
May 9, 2013, 9:59:13 AM5/9/13
to Norm Rubin, dev-tech-js-en...@lists.mozilla.org
The current design permits free access to variables from within
closures, and this is one of its selling points (and not something I
would personally even consider removing). In any case, even if we did
somehow limit ourselves to closures without an environment---a foreign
concept in JavaScript, though one that might be useful in various
applications---it wouldn't help that much. JavaScript is just not
designed for effect isolation. First off, there are global variables
(which are in fact the default) and, secondly, every object has access
to its (mutable) prototype chain, which is also global state.


Niko
> _______________________________________________
> dev-tech-js-engine-rivertrail mailing list
> dev-tech-js-en...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-tech-js-engine-rivertrail
0 new messages