(a, (b, *c, d), *e) = [1, (2, 3, 4, 5), 6, 7]
Good for nested iterables, but not supporting dict/object unpacking. (a, (b, *c, d), *e) = [1, (2, 3, 4, 5), 6, 7]
Good for nested iterables, but not supporting dict/object unpacking.http://www.dai.ed.ac.uk/groups/ssp/bookpages/quickprolog/nod...
[Amused to see that the page I linked to there is over 20 years old!]
When I first read that, I thought he meant run-time lookups of overloaded method names, which is a form of pattern matching on parameter lists.
https://www.artima.com/weblogs/viewpost.jsp?thread=101605
Five-minute Multimethods in Python, by Guido van van Rossum.
I used to believe that multimethods were so advanced I would never need them. Well, maybe I still believe that, but here's a quick and dirty implementation of multimethods so you can see for yourself. Some assembly required; advanced functionality left as an exercise for the reader.
https://python-3-patterns-idioms-test.readthedocs.io/en/late...
https://pythonhosted.org/multidispatch/
https://adambard.com/blog/implementing-multimethods-in-pytho...
https://opendylan.org/documentation/intro-dylan/multiple-dis...
https://opendylan.org/documentation/intro-dylan/objects.html...
say &infix:«+».candidates.elems; # 27
Here is a quick translation of that second link to Perl6 #! /usr/bin/env perl6
use v6.d;
enum Roshambo < Rock Paper Scissors >;
enum Outcome < Lose Win Draw >;
proto compete ( Roshambo, Roshambo --> Outcome ){*}
multi compete ( Paper, Rock --> Win ){}
multi compete ( Rock, Scissors --> Win ){}
multi compete ( Scissors, Paper --> Win ){}
multi compete ( $a, $b where $b eqv $a --> Draw ){}
multi compete ( $, $ --> Lose ){}
for Roshambo.roll(20) Z Roshambo.roll(20) -> ($a,$b) {
say "$a.fmt('%8s'), $b.fmt('%8s'): &compete($a,$b)"
}
(Note that I didn't really write any actual code for the `compete` subroutines; it was all handled by the signatures.)