Re: [fpc-devel] New feature discussion: LAMBDA

2009-10-22 Thread Michael Schnell
Jeff Wormsley wrote:
  One of the reasons I like Pascal
 is that you do usually have to spell out what you are doing.  It makes
 reading the code months or years later, or reading someone else's code
 much easier. 

That is why I never use with.

For me with severely brakes the paradigm you state.

-Michael
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] New feature discussion: LAMBDA

2009-10-21 Thread Michael Schnell
Jeff Wormsley wrote:
 Wow, talk about unreadable code...
 

In fact I did not ever try to understand this. I just happened to  know
about Lambda in Prism and wanted to let the forum share that.

 I'm all for saving typing, but not at the expense of readability.  

Agreed.

 This
 reminds me of C's oddball ? operator.  

In fact I think that the ? operator in C is easily readable (But of
course in C you easily can create unreadable code by e.g. doing
assignments in if-clauses.
  if (a=b) a=1;

which happens to translate in Pascal as:
  a:=b;
  if a0 then a:=1;

-Michael
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] New feature discussion: LAMBDA

2009-10-21 Thread Dariusz Mazur

Jeff Wormsley pisze:


Michael Schnell wrote:

Again something inspired by Delphi-Prism ?

( http://prismwiki.codegear.com/en/Lambda_Expressions )

Wow, talk about unreadable code...


why all vote about something, that wasn't proposed ?



--
 Darek




___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


[fpc-devel] New feature discussion: LAMBDA

2009-10-20 Thread Dariusz Mazur

Hi
Based on discussion about for in I want to suggest my proposition.
When we investigate some code, sometimes we found pattern:

Pattern 1:
/  begin
   startfun;
   try
 ...
   finally
 stopfun;
   end;
/  end;

Pattern 2:
 for i:= startfun to stopfun do begin

 end;


Pattern 3:
 startfun;
 while stopfun do begin
   ...
 end;


Common for all mentioned patterns are two connected functions, which 
controlled running of body source. First make all initializations, 
second  helping with iterations and finalizations.


My proposition is make possibility of join, those  pair to one  
sentence. All patterns can be change to one common template:


  if startfun then repeat
  until stopfun;
 
I You see we need two function with boolean result. Of course 
possibility of parameters give wide appliance.


To preserve  pascalish  style I propose something like this:

tMyObject = class(tObject)
  function startfun:boolean;
  function stopfun:boolean;
 property lambdafun; start startfun stop stopfun;
end;

and invoke:
 
 var

  t : tMyObject;
 begin
  ..
  t.lambdafun do begin
 
  end;
 end;

because on declaration side is similar do properties (also two function) 
we can use the same syntax. Only keyword  start and stop  exchange  read 
and write.


To using i thought  about  WITH, but it may confusing bit, thus  I 
propose omit, and only use keyword DO.


Why lambda. Because is very similar to constructing no name procedures 
and use them as normal. We have few mechanism controlling runnig: IF, 
REPEAT, WHILE, FOR. They work well, but sometimes they are week. For 
example we don't have enough primitives do build own implementation 
FORIN method, on iterators also. But in Lisp any mechanism, any sequence 
of computing collection can be done and source is very readable

 lisp syntax: (lambda (formal parameters) body)
This is not unusual, but we can send this declaration as argument of 
procedure.

Of course syntax like this
  tlist.foreach( procedure (x : tObject);begin writeln(x) end)

is ugly (thought I sow something similar in  C++/boost)
but when we change it a bit:

 tlist.foreach(x) do  begin
   writeln(x);
 end;

its not so strange

Because my english is very poor I only show some application

EXP. mutex (and patterns as RIAA)

   tMutex = class
 property makeatomic; start lock stop unlock;
   end;
 .

 begin
   tMutex.makeatomic do begin
 ...
   end;
 end; 


EXP: foreach


  tMyList = class

function tMyList.start:boolean;

begin
  current:=first;
  result:=currentnil; 
end;

function tMyList.stop:boolean;
begin
  current:=next(current);
   resutl:=currentnil;
end; 



When attributes are added, or exception caching this will be more flexible.





--
 Darek





___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] New feature discussion: LAMBDA

2009-10-20 Thread Michael Schnell
Again something inspired by Delphi-Prism ?

( http://prismwiki.codegear.com/en/Lambda_Expressions )

-Michael
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] New feature discussion: LAMBDA

2009-10-20 Thread Dariusz Mazur

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@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] New feature discussion: LAMBDA

2009-10-20 Thread Jeff Wormsley


Michael Schnell wrote:

Again something inspired by Delphi-Prism ?

( http://prismwiki.codegear.com/en/Lambda_Expressions )

Wow, talk about unreadable code...

I'm all for saving typing, but not at the expense of readability.  This 
reminds me of C's oddball ? operator.  One of the reasons I like Pascal 
is that you do usually have to spell out what you are doing.  It makes 
reading the code months or years later, or reading someone else's code 
much easier.  So it might not be the most efficient in terms of typing, 
or even compilation or execution, but the savings in maintenance more 
than make up for it.  The examples given at that site would drive me 
crazy.  I don't believe I'll be using Prism any time soon.


Jeff.
--
I haven't smoked for 3 years, 2 months and 3 days, saving $5,222.69 and 
not smoking 34,817.99 cigarettes.

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] New feature discussion: LAMBDA

2009-10-20 Thread ik
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 dar...@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@lists.freepascal.org
 http://lists.freepascal.org/mailman/listinfo/fpc-devel

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] New feature discussion: LAMBDA

2009-10-20 Thread Marco van de Voort
In our previous episode, Jeff Wormsley said:
  ( http://prismwiki.codegear.com/en/Lambda_Expressions )
 Wow, talk about unreadable code...
 
 I'm all for saving typing, but not at the expense of readability.  This 
 reminds me of C's oddball ? operator.  

(hmm, if I would name one feature I hate about C, that would be that if (x=y)
goes unnoticed while legal. At least the ? operator doesn't bite you if you
don't use it)

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] New feature discussion: LAMBDA

2009-10-20 Thread Vincent Snijders

Marco van de Voort schreef:


(hmm, if I would name one feature I hate about C, that would be that if (x=y)
goes unnoticed while legal. At least the ? operator doesn't bite you if you
don't use it)


Off topic.

Vincent
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] New feature discussion: LAMBDA

2009-10-20 Thread Graeme Geldenhuys
2009/10/20 Jeff Wormsley dawor...@comcast.net:

 ( http://prismwiki.codegear.com/en/Lambda_Expressions )

 Wow, talk about unreadable code...

+1

That's all I can say.


-- 
Regards,
  - Graeme -


___
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] New feature discussion: LAMBDA

2009-10-20 Thread Dariusz Mazur

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 dar...@emadar.com mailto:dar...@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@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel