Created
September 16, 2016 21:05
-
-
Save darius/cf46925bbb4f4f3bf38e6abdb1444573 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# h/t Dave Long | |
from collections import namedtuple | |
data = lambda s: {ws[0]: namedtuple(ws[0], ws[1:]) | |
for term in s.split('|') for ws in [term.split()]} | |
Data = lambda s: globals().update(data(s)) | |
Data("Nil | Cons head tail") | |
Nil .length = lambda xs: 0 | |
Cons.length = lambda xs: 1 + xs.tail.length() | |
## Cons(42, Cons(137, Nil())).length() | |
#. 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment