[fpc-devel] New feature discussion: LAMBDA

Dariusz Mazur darekm at emadar.com
Tue Oct 20 23:32:57 CEST 2009


ik pisze:
> 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.
You don't understand me. I know sub process, this is nice feature of 
pascal, but i talk about something different.

Sometimes we have sub process and want to do with them rather 
complicated task.
> 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;
My example was different. Try to implement my example with the same 
readability, error prove,
>
> 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.
I don't draw from C++, which is imperative language , rather try to use 
some of the best of functional language.
I don't even know, that it should be name lambda. Its similar to 
iterators, but also to aspect. It has the same syntax as properties. 
thats all.

>
> 2009/10/20 Dariusz Mazur <darekm at emadar.com <mailto: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







More information about the fpc-devel mailing list