Who wants full block closures and why?

Vassili Bykov vassili at objectpeople.com
Mon Jul 19 19:08:20 UTC 1999


> From: David N. Smith (IBM) [mailto:dnsmith at watson.ibm.com]
>
> So, closures have copies of external variable references from the
> point at which they are created?

No, closures capture their lexical environment without making any copies.
In the following:

  | foo |
  ^Array
    with: [foo]
    with: [:arg | foo := arg]

passing an object to the second closure should change the value answered by
the first.  Both closures share the same binding of 'foo'.

In the VA implementation it is not the closure creation that is
questionable, it is the iteration (#to:do:).  It should create a new binding
of 'i' at each iteration (closures are supposed to create fresh bindings for
their arguments before each evaluation), so closures in the 'blockArray'
created at different iterations should capture *different* bindings of 'i'.
As Allen Wirfs-Brock already pointed out, because of #to:do: inlining no
closure is actually created for the iteration block, so all iterations share
the same binding of 'i' which is reassigned between block invocations.  As
long as blocks are claimed to be closures, and as long as the second
argument to #to:do: looks like a block, this should not be happening.

--Vassili

--
Vassili Bykov        <vassili at objectpeople.com>
The Object People    <http://www.objectpeople.com>
  "Any sufficiently complicated C or Fortran program contains
  an ad-hoc, informally-specified bug-ridden slow implementation
  of half of Common Lisp."  --Greenspun's Tenth Rule of Programming





More information about the Squeak-dev mailing list