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
# A quick proof-of-concept. There is some room for improvement. | |
# Note also that Clojure's macros have no loss of performance compared to writing their expansion (i.e. nested calls) in the first place. | |
# This, on the other hand, creates a new object per nesting. Python is very flexible, but it's not fast. | |
class Thead: | |
""" | |
Thread-Head class. Like Clojure's -> (thread-first) macro. | |
>>> import operator as op | |
>>> Thead(5)(op.sub, 3)(op.mul, 10).result | |
20 |