4 ms·
It's definitely leaning toward the functional side, but some things look very odd (like calling "filename".IO...). The new operators leave me dubious (eg, '*' t
by mercurial 12y ago
It's definitely leaning toward the functional side, but some things look very odd (like calling "filename".IO...). The new operators leave me dubious (eg, '*' to create a one-argument lambda function). And '»'? At least the equivalent '>>' is apparently available, but damn...
- delluminatus 12y agoThe * operator made me laugh out loud. Only Perl would have an operator called a "Whatever star". Although, I actually think a lot of the stuff Perl does is really cool. I wouldn't want to have to maintain a codebase of it, but it never fails to be interesting. Like the whatever star. "*.value" basically saying, "Whatever value is here, gimme the value of it". It's different from a typical lambda declaration, but intuitive in its own way.
- munificent 12y ago> It's different from a typical lambda declaration, but intuitive in its own way. Isn't it pretty similar to Scala's use of "_"? I think _.value creates a one-parameter lambda in Scala.
- tormeh 12y agoYeah, but it would be neat if it was a word instead, for example "that". "*" is hilarious, though. How do you multiply in Perl if the star is taken? I also like that it's named "whatever star", reminds me of Scala's Pimp my Library feature[0] 0: http://www.artima.com/weblogs/viewpost.jsp?thread=179766 http://www.artima.com/weblogs/viewpost.jsp?thread=179766
- cygx 12y agoAn asterisk is only a Whatever if it's in term position: (* * *)(2, 3) will happily print 6.
- SwellJoe 12y agoI didn't find the whatever star funny until this point.
- pwr22 12y agoWhatever ;)
- Ultimatt 12y agoI'd like to point out there are magical errors put in to keep Perl6 code relatively sane too: > .map: ** * * * ** ===SORRY!=== Error while compiling <unknown file> Multiple HyperWhatevers and Whatevers may not be used together
- esaym 12y agoPerl has always had something called "context" :)
- muraiki 12y agoClojure has %: (map #(/ % 2) [2 4 6 8]) => (1 2 3 4) (map #(% 2) [#(- 2 %) #(* 2 %)]) => (0 4) (#(+ %1 %2 %3) 2 4 6) => 12
- Ultimatt 12y agoIt's not just one argument! I't consumes as many arguments as you like, there is also the HYPER WHATEVER which is two asterisc in a row * * (without white space a limitation of HN!) which is a dimensioned form of whatever for dealing with higher dimension data structures. The following are identical with and without whatever: perl6> "ACAGATAAATTA".comb.map: * ~ * ~ * ; ACA GAT AAA TTA perl6> "ACAGATAAATTA".comb.map({$^first ~ $^second ~ $^third}); ACA GAT AAA TTA It's worth pointing out we're lucky that 'first' is lexically before 'second' in the second one though. The $^ consumes parameters in the lexical order of the variable names. So it's used normally for $^a $^b in sorting. So .sort({$^a cmp $^b}) versus .sort({$^b cmp $^a}). But a general feature was made rather than an obscure exception. In general Perl6 is very consistent. It might also just be a bit too crazy at times, some of the stuff you can do like the (* * *)(2,3) below you obviously would just not do in real life. So an example where the lexical ordering is kind of neat: perl6> "ACAGATAAATTA".comb.map({$^third ~ $^second ~ $^first}); ACA TAG AAA ATT Contrived since you could just split the string by three characters and flip it :P But hopefully you get the idea!