improving '$' to work with other functions (eg: indexed)
Jonathan M Davis
jmdavisProg at gmx.com
Thu Oct 31 15:37:00 PDT 2013
On Thursday, October 31, 2013 14:46:29 Timothee Cour wrote:
> well it can be made to work with following rule:
>
> $ binds as follows, using the 1st pattern matched rule:
>
> very roughly:
>
> identifier [$] if typeof(a.length) => a[a.length] //likewise with s/[]/()/
> primary_expression . identifier if typeof(primary_expression.length)
> => primary_expression . identifier [identifier.length] (recursively)
> if no match is found, error.
>
> eg:
>
> [1,2,3].indexed([0,$-1] ) => indexed.length isn't valid, so it tries to
> bind to [1,2,3].
>
> intuitively I believe it makes sense.
Well, I can see why you'd think that that makes sense, but it would have
surprised me greatly if I had seen code like that compile. And given how
little benefit it really provides, I don't think that it's worth the extra
complication to the language. So, I'd be against it, but feel free to open an
enhancement request. Maybe a compiler dev will take a shine to the idea.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list