Future of string lambda functions/string predicate functions

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Aug 14 09:37:30 PDT 2013


On Wed, Aug 14, 2013 at 09:26:20AM -0700, Andrei Alexandrescu wrote:
> On 8/14/13 7:34 AM, H. S. Teoh wrote:
[...]
> >That's a bit too terse. What about this:
> >
> >	less		// a < b
> >	less!(5)	// a < 5
> >	lessEq		// a <= b
> >	lessEq!(5)	// a <= 5
> >	more		// a > b
> >	more!(5)	// a > 5
> >	moreEq		// a >= b
> >	moreEq!(5)	// a >= 5
> >	equal		// a == b
> >	equal!(5)	// a == 5
> >	notEqual	// a != b
> >	notEqual!(5)	// a != 5
> 
> At this point using "a < b" for a < b, "a < 5" for a < 5 etc.
> becomes awfully attractive.
[...]

It just occurred to me, that perhaps what we really need here is an
even more abbreviated form of lambda literals, like this:

	sort!(a < b)(range);

where 'a' and 'b' are undefined identifiers in the current scope, and
the compiler would know to bind them to lambda parameters. Defined
identifiers would, naturally, bind to whatever they refer to:

	int x = 5;
	find!(a == x)(range);

This would be equivalent to:

	int x = 5;
	find!((a) => a==x)(range);

IOW, an expression that references undefined identifiers in a template
parameter would be turned into a lambda that parametrize said
identifiers.


T

-- 
Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald Knuth


More information about the Digitalmars-d mailing list