Future of string lambda functions/string predicate functions

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Aug 8 07:29:56 PDT 2013


On Tue, Aug 06, 2013 at 11:05:56AM +0200, Jakob Ovrum wrote:
> In Phobos pull request #1453 (Implement chunkBy.)[1], the topic of
> string lambda functions has again cropped up. I think we should
> clearly decide on some things regarding them. Questions such as; are
> they a worthwhile alternative in the present language? Should they
> be deprecated? Should they be supported in new additions to Phobos?
> 
> Some background: string lambda functions are a feature of
> std.functional/std.range/std.algorithm, where strings can be passed
> in lieu of functions as template alias arguments to various public
> functions in these modules. The string becomes the return expression
> of an anonymous function which implicitly has one or two arguments,
> named "a" and "b", like the string "a < 3" in the following example
> expression:
> 
>   arr.filter!"a < 3"
> 
> When this feature was developed, there were no lambda function
> literals in the language. There were anonymous functions, but their
> syntactical overhead means they fare poorly as a replacement for
> lambda functions:
> 
>   arr.filter!((a) { return a < 3; })
> 
> The effect is particularly jarring in bigger compositions:
> 
>   assert([ 1, 2, 3, 4, 5 ].filter!((a) { return a < 3; }).equal([1,
> 2]));
> 
> Since then, a first-class lambda syntax has been introduced, with
> significantly less syntactic overhead:
> 
>   arr.filter!(a => a < 3)
> 
> The issue is then: is the old string lambda syntax obsolete in the
> face of the new lambda literals?
[...]

Seems this thread has quietened down. So, what is the conclusion? Seems
like almost everyone concedes that silent deprecation is the way to go.
We still support string lambdas in the background, but in public docs we
promote the use of the new lambda syntax. Would that be a fair
assessment of this discussion?

What about new Phobos functions? Should we continue to support string
lambdas in new code?


T

-- 
Life is unfair. Ask too much from it, and it may decide you don't deserve what you have now either.


More information about the Digitalmars-d mailing list