3 ms·
[minor syntax/markup edits] One that has caught my fancy are various uses of the "Whatever Star". This appears as a * in a few contexts. In many it is really a
by awwaiid 11y ago
[minor syntax/markup edits]
One that has caught my fancy are various uses of the "Whatever Star". This appears as a * in a few contexts. In many it is really a shortcut for the "Whatever" class, so you can use it in function signatures to enter sort of "automatic mode".
@shuffled_names = @names.pick(*) # randomly pick... however many you have. whatever.
But I think more interesting and different than that is using whatever-star as an automatic lambda thing.
@nums.map(*/2 + 3) # expression-lambda from context around a whatever-star
@nums.map( -> $n { $n/2 + 3 } ) # equivalent with a real stabby arrow lambda
@nums.map( { $^n/2 + 3 } ) # $^n is a generated alphabetical-positional argument
I suppose this isn't really fundamental... but is definitely different.
- deleted 11y ago[deleted]
- wantarray 11y agoI'm pretty sure that the "expression-lambdas" were inspired by Haskell, where you get a lambda simply by writing an operator with one or more missing operands. In Perl 6, detecting that an operand is "missing" isn't possible due to the existence of prefix/infix/postfix operators with the same names, so it expects a "whatever" star in place of the missing operand... :)