On 24 December 2014 at 06:30, Geoffrey Irving <[email protected]> wrote:
> In python,
>
>     closures = []
>     for i in range(10):
>       closures.append(lambda x:x+i)
>
> makes 10 copies of lambda x:x+9.

Ho-hum.  I'm not sure what sense it makes to talk about a language
that doesn't have variable declarations in this context, because if
you insert them where python conceptually does, this example makes
sense.  In particular, it allows you to do:

def make_even():
    # var even, odd
    even = lambda n: True if n == 0 else odd(n - 1)
    odd = lambda n: False if n == 0 even(n - 1)
    return even

How did even() get a binding to odd before it was set?  because it
captured the unbound local from the mutable environment.  I think it
would be nonsense for this example /not/ to work.  The "mutability
inference", to the extent such a thing exists, is working correctly.

The *other* possibility is to say that the variable introduced by the
loop is fresh, as in the following java:

for ( final int i : someIterable ) {
  closures.append(x -> x + i);
}

If you don't require variable declarations, this seems a bit tricky,
because does the loop body also introduce a fresh scope?  Java says
yes, but this is awkward in practice.

-- 
William Leslie

Notice:
Likely much of this email is, by the nature of copyright, covered
under copyright law.  You absolutely MAY reproduce any part of it in
accordance with the copyright law of the nation you are reading this
in.  Any attempt to DENY YOU THOSE RIGHTS would be illegal without
prior contractual agreement.
_______________________________________________
bitc-dev mailing list
[email protected]
http://www.coyotos.org/mailman/listinfo/bitc-dev

Reply via email to