2 ms·
Hofstadter, Friday and Perl 6 – Arne Sommer
- ktpsns 7y agoHaven't used Perl since decades, $foo.=bar raised an eyebrow but I had a dawn of an idea what hell of a drug this is. Turns out, yes: It's syntactic sugar for $foo=$foo.bar() method invocation. Ref: https://docs.perl6.org/language/operators#methodop_.= https://docs.perl6.org/language/operators#methodop_.= I fucking love Perl for this kind of shit! It allows to write super short programs which you can very well read, even better then super verbose traditional OOP languages.
- b2gills 7y agoEven better than that, if you create a new infix operator: sub infix:<OP> ( $a, $b ) {…} You get `OP=` for free: $x OP= $y; # $x = $x OP $y That is because `=` is actually a meta operator. (It takes an infix operator as a sort-of argument.) $x [OP]= $y; # more explicit that `OP` is an argument to `=` --- You could also just use a regular subroutine as if it was an infix operator: sub foo ( $a, $b ) {…} $x [&foo] $y; # foo( $x, $y ) So you can also use it with the `=` meta operator: $x [&foo]= $y; # $x = foo( $x, $y )
- ktpsns 7y agoSome people demonize languages for adding syntactic suggar, but I think this is what can make them really great. It raises the language (perl6 in this case) to a meta programming level. In a similiar way people refer to LISP as a meta programming language (while there the "meta" stems from the powerful macro language which again is LISP). I love that.