[fpc-devel] New feature discussion: LAMBDA
Dariusz Mazur
darekm at emadar.com
Tue Oct 20 19:17:54 CEST 2009
Michael Schnell pisze:
> Again something inspired by Delphi-Prism ?
>
> ( http://prismwiki.codegear.com/en/Lambda_Expressions )
>
>
No at all, I don't even see this before. I thing long about this. But
lately I see this in C++ (strange) and Lisp (beautiful)
In Prism have You:
c -> c.Name = 'Smith'
which is very strange, special syntax, and need to be translate to "method", and declaration longer
than one line is awful,
my proposition semantically is between properties (they consist also two function),
aspect programming and lambda
is very easy to translate to ordinal pascal( lambda invoke change to repeat-while iteration,
similarly as in generics)
has wider application:
from FPC WIKI:
procedure StringLoop(S: String);
var
C: Char;
begin
for C in S do
DoSomething(C);
end;
my prop:
procedure stringloop(s :tMyString);
begin
{with} s.eachword do begin
if s.currentword<>'begin' then
writeln(s.currentword);
end;
end;
of course I can write
procedure stringloop(s :tMyString);
begin
s.firstWord;
try
while s.nexword do begin
if s.currentword<>'begin' then
writeln(s.currentword);
end;
except
s.exceptWord;
end;
end;
which can be equivalent
from compiler side invoke of lambda is translate to proper iteration before main compilation
from developer side: its easy to use as properties,
fewer bugs caused forget of initialization or finalization, or use incompatible init and step
function in iterators
--
Darek
More information about the fpc-devel
mailing list