We need closures
Mildred Ki'Lya
ml.mildred593 at online.fr
Mon Sep 8 08:53:37 UTC 2008
Not really my saying (even if it could or was):
http://notes-on-haskell.blogspot.com/2008/09/closures-are-coming.html
Short summary, closures are being implemented in C (LLVM+clang,
initiated by Apple for ObjectiveC)
Basically, closures are functions that can be passed as values and that
reference variables from outside of the function. The tricky part of
implementing them is when the function is called at a moment where the
variables it uses are no longer then.
Imagine the Lisaac code:
- return_a_closure initial_value:INTEGER :{;INTEGER} <-
( + count :INTEGER;
count := initial_value - 1;
{
count := count + 1;
count
}
);
- uses_a_closure <-
( + closure :{;INTEGER};
closure := return_a_closure 1;
closure.value.println; // 1
closure.value.println; // 2
closure.value.println; // 3
closure.value.println; // 4
);
Unfortunately, such code is likely to raise an error, the compiler
saying that the BLOCK is used outside the variable 'count' scope.
This is just to illustrate the concept of closure, not its usefulness.
Mildred
--
Mildred Ki'Lya
╭───────── mildred593@online.fr ──────────
│ Jabber, GoogleTalk: <mildred at jabber.fr>
│ Site: <http://ki.lya.online.fr> GPG ID: 9A7D 2E2B
│ Fingerprint: 197C A7E6 645B 4299 6D37 684B 6F9D A8D6 9A7D 2E2B
More information about the Lisaac-devel
mailing list