|
Perl 6
Perl 6 Operator Tablet: Revision 26
Overview - Chapter: 0:History, 1:Design, 2:Basics, 3:Var, 4:Op, 5:IO, 6:{}, 7:Sub, 8:OOP, 9:Rx, 10:Meta Perl folkore: Perl is an operator based language. Perl 6 has a huge amount of operators, because they support 2 of the main design goals: they offer dense and readable code. 2 + 3 is certainly shorter and easier to understand then add(2,3), since pictograms can be picked up faster than words. (Fortran made his whole carrier on that). But because they are so many, they had to be sorted by a rule named huffman coding, which was applied here more than in any other part of the syntax. To understand an operator you have to know his arity (how many parameters he takes - usually one (!) or two (+) ). The precedence tells which operator to prefer in case of conflict, when no braces are used (round braces are only used for grouping and managing precedence). It allows 2 + 3 * 5 to return 17, not 25, which would upset your math teacher. Behind that link is a table which also tells you also the associativity of every operator. This tells you after which rule to resolve precedence if one operator is used several times like in 2 * 3 * 7. Comparison and testing in the scalar contextSmartmatchThis is most likely the mother of all Perl 6 operators and can be called the compare-this-with-that-operator". Because he allows to relate nearly everything with everything (it's much more powerful than the small version, backported into 5.10), its "behaviour is complex, even he tries to do just what you expect him to do. ~~ !~ Equalityeqv eq == === Traversing Sequence++ -- succ pred Generic Comparsionbefore after cmp Numerical Comparsion< == > <=> <= >= String Comparsionlt eq gt leg le ge joined comparison3 < $a == $a < 7 is not the same as 3 < $a < 7 because latter is evaled at once and the first in 2 steps (left to right) Junctions| & ^ Ranges.. ^ logical selection&& - and see also numerical selection ternary?? !! flipflopff fff file testyadda... context forcing scalar opsbool context? ! numeric context+ - * ** / % %% numerical selectionmin max minmax String context~ x Ops for arrays/listsList generationThe simplest way to create a list is by repeating some values: 'munch' xx 3 # results in 'munch', 'munch', 'munch' In list context the range operator produces lists: @ 2 .. 7 --> 2,3,4,5,6,7 Sequence Operator... ZipZ CombinatorsX Hyperops<< >> Reduce[ ] Triangle[\ ] Feed Ops<== ==> Assignment opsself assigning opsprecedence tableintentionally not existing opsmaking own operators
Overview - Chapter: 0:History, 1:Design, 2:Basics, 3:Var, 4:Op, 5:IO, 6:{}, 7:Sub, 8:OOP, 9:Rx, 10:Meta |