Parameterized Keywords
Patience via Digitalmars-d
digitalmars-d at puremagic.com
Sun Mar 6 21:56:54 PST 2016
Just curious if anyone can see the use for them?
e.g., for[32], switch[alpha] //alpha is a user type, if[x](x < 32)
etc..
The idea is two-fold, one is to allow polymorphic keyword
behavior(it's behavior depends on the argument) and to allow the
code itself to manipulate the behavior.
Of course, the behavior isn't easily define for the above
examples. So far all I can think of is various simple
modifications:
foreach[?] <- executes only if there are one or more iterations
and checks for nullity. This allow one to avoid writing the if
check.
int[size] <- creates an integer of size bits.
etc...
I can't see much benefit but maybe someone has some good uses?
These could be thought of as "attributes for keywords". The
programmer would have to define precisely what if[x] means.
Obviously the biggest objection is "It will obfuscate
keywords"... Please don't obfuscate the question with such
responses.
More information about the Digitalmars-d
mailing list