www.digitalmars.com         C & C++   DMDScript  

D - Anonymous functions?

reply Andy Friesen <andy ikagames.com> writes:
Basically, some syntactic sugar for small functions that are only needed 
for a moment.

	alias void delegate(int i) Function;
	Function f = Function { return i * 3 };

Or somesuch.  If one wants to get fancy, one could get the compiler to 
try and inline them when passed as template arguments, which opens the 
doorway to C++ STL-like algorithms.

	instance Algorithm(SomeType,
		Comparer {
			return a.something > b.something;
		}
		).Sort(somearray);

Maybe the syntax isn't so hot, though.
Feb 01 2003
next sibling parent "Carlos Santander B." <carlos8294 msn.com> writes:
"Andy Friesen" <andy ikagames.com> escribió en el mensaje
news:b1h5uk$2omp$1 digitaldaemon.com...
| Basically, some syntactic sugar for small functions that are only needed
| for a moment.
|
| alias void delegate(int i) Function;
| Function f = Function { return i * 3 };
|
| Or somesuch.  If one wants to get fancy, one could get the compiler to
| try and inline them when passed as template arguments, which opens the
| doorway to C++ STL-like algorithms.
|
| instance Algorithm(SomeType,
| Comparer {
| return a.something > b.something;
| }
| ).Sort(somearray);
|
| Maybe the syntax isn't so hot, though.
|

What about functions inside other functions (what's the real name for that),
like in Delphi? I'm not sure about the syntax, but maybe that could be a
workaround (sp?) for anon functions. Or am I getting it wrong?

-------------------------
Carlos Santander
http://carlos3.netfirms.com/
"Andy Friesen" <andy ikagames.com> escribió en el mensaje
news:b1h5uk$2omp$1 digitaldaemon.com...
| Basically, some syntactic sugar for small functions that are only needed
| for a moment.
|
| alias void delegate(int i) Function;
| Function f = Function { return i * 3 };
|
| Or somesuch.  If one wants to get fancy, one could get the compiler to
| try and inline them when passed as template arguments, which opens the
| doorway to C++ STL-like algorithms.
|
| instance Algorithm(SomeType,
| Comparer {
| return a.something > b.something;
| }
| ).Sort(somearray);
|
| Maybe the syntax isn't so hot, though.
|

What about functions inside other functions (what's the real name for that),
like in Delphi? I'm not sure about the syntax, but maybe that could be a
workaround (sp?) for anon functions. Or am I getting it wrong?

-------------------------
Carlos Santander
http://carlos3.netfirms.com/
Feb 01 2003
prev sibling parent reply "Walter" <walter digitalmars.com> writes:
Anonymous functions (in some form) are a very good idea. -Walter
Feb 18 2003
parent Mark Evans <Mark_member pathlink.com> writes:
Microsoft considered functional language features important enough to enhance
NET.  D should pay them serious attention.  -M.

http://research.microsoft.com/projects/ilx/babel01.pdf
Feb 19 2003