[fpc-pascal] Re: Functional Pascal

Lukasz Stafiniak lukstafi at gmail.com
Thu Mar 1 12:47:35 CET 2012


On Thu, Mar 1, 2012 at 12:21 PM, Lukasz Stafiniak <lukstafi at gmail.com> wrote:
>
> Wow, I didn't know about that! Still, it is not clear to me it is a
> good thing to capture "var" variables in the closure. It goes against
> the semantics of normal nested functions. It's a "dirty but flexible"
> solution -- it makes it easy to define several closures out of a
> single definition (kind of like using partial application), e.g. when
> the anonymous function is inside a loop. Java doesn't have it
> (closures can only refer to "final" variables, "final"="val"="let").

I'm sorry, I got confused -- the closure in Pascal does not capture
the value of the variable (i.e. does not form a copy of the variable),
rather, the variable becomes heap-allocated (implicitly a field of
some class), and anonymous functions together with the function that
contains them share the variable. Making a copy would be an
interesting design choice... (although violating the semantics of
nested procedures.)

http://www.reddit.com/r/programming/comments/6tp3i/pascal_gets_closures_before_java_why_hasnt_the/



More information about the fpc-pascal mailing list