Skip to content

Instantly share code, notes, and snippets.

@arunbear
arunbear / lvalue.pl
Created December 26, 2020 16:39
lvalue methods in Perl
pirl @> sub hats : lvalue { my ($self) = @_; $self->{hats}; }
@var = ();
pirl @> $obj = bless {}
@var = (
bless( {}, 'Shell::Perl::sandbox' )
);
pirl @> $obj->hats
@var = (
undef
);
@arunbear
arunbear / mm.py
Created March 26, 2020 17:29
Multimethods in Python
# Example usage of https://www.artima.com/weblogs/viewpost.jsp?thread=101605
# with added commutativity
import itertools
registry = {}
class MultiMethod(object):
def __init__(self, name):
self.name = name