[fpc-devel] New feature discussion: LAMBDA

ik idokan at gmail.com
Tue Oct 20 19:49:06 CEST 2009


Pascal have something close to lambda, and it's nested functions/procedures

The original idea of lambda is to have sub process that takes parameters and
simple tasks.
For example (in Ruby):

def action(base)
  expo = lambda { |by_num| base ** by_num}
  x = something
  a = expo(x)
  ....
end

I can do the same with the following:

procedure action(base : integer)
  function expo(by_num)
  begin
    expo := base ** by_num
  end;
var x,a : integer;
begin
   x := something;
  a := expo(x);
 ...
end;

Of curse it's one usage for it, but most of the real usage of lambda can be
made in pascal today. And please do not take ideas from C++, it's a language
that wrote on it's agenda to implement any possible technology out there
regardless of it's need or  usage, and it's impossible to use that language
without some framework or ignoring this technologies.

Ido
http://ik.homelinux.org/


2009/10/20 Dariusz Mazur <darekm at emadar.com>

> 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
>
>
>
>
>
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20091020/94e6cd86/attachment.html>


More information about the fpc-devel mailing list