Future of string lambda functions/string predicate functions
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Wed Aug 14 09:26:20 PDT 2013
On 8/14/13 7:34 AM, H. S. Teoh wrote:
> On Wed, Aug 14, 2013 at 09:10:37AM +0200, Tyler Jameson Little wrote:
>> On Wednesday, 14 August 2013 at 05:44:50 UTC, Brad Anderson wrote:
>>> On Wednesday, 14 August 2013 at 02:05:16 UTC, Manu wrote:
>>>> Can you give an example where you've actually used a string lambda
>>>> before where the predicate is more complex than a basic comparison?
>>>> Surely the solution to this problem is to offer a bunch of templates
>>>> that perform the most common predicates in place of unary/binaryFun?
>>>>
>>>> So rather than: func!((a, b) => a < b)(args)
>>>> You use: func!binaryLess(args)
>>>>
>>>> Or something like that?
>>>>
>>>
>>> How about just "less"? It's what C++ STL uses (std::less,
>>> std::greater, std::negate, etc...). In C++, however, you have to
>>> do some truly ugly stuff to actually make use of the predefined
>>> function objects...bind1st...eww (the new C++11 bind is only
>>> marginally better but C++11 does have lambdas now at least).
> [...]
>> Or imitate bash:
>>
>> Binary:
>> - gt: a > b
>> - ge: a >= b
>> - lt: a < b
>> - le: a <= b
>> - eq: a == b
>> - ne: a != b
>>
>> Unary:
>> - z: (zero) a == 0 (if range, a.empty?)
>> - n: (non-zero) a != 0
>>
>> Perhaps this is *too* terse?
>
> 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.
Andrei
More information about the Digitalmars-d
mailing list