4 ms·
A python decorator is just a syntactic sugar for : f = decorator(f) Afaik, the decorator deals with the internal function as a black box. But with lisp being
by kopos 7y ago
A python decorator is just a syntactic sugar for :
f = decorator(f)
Afaik, the decorator deals with the internal function as a black box.
But with lisp being a lisp, the macro writer can choose the level of blackboxiness they want to deal with.
Note: I love both Python and Clojure and use them extensively.
- dangerbird2 7y agoAs others have hinted at, higher-order functions like decorators can inspect and manipulate the internals of a "black box" function object with the ast module[1]. This would be comparable to a lisp function taking a quoted form, expanding and evaling it at runtime as an ad-hoc macro funcitonality as is common in more bare-bones lisp implementations. Aside from the ease of manipulating quoted forms (i.e. asts) in Lisp and Clojure, a big part of the power of defmacro and kin is that Lisps distinguish (depending on implementation) between read-time, macroexpand-time, compile time, and eval time, giving the macro author control over when and where the macro is executed as well as how. As an example, this makes things like lazy evaluation (without requiring users to explicitly "thunk" values into functions) trivial to implement in lisp [1] https://docs.python.org/3/library/ast.html https://docs.python.org/3/library/ast.html
- kopos 7y agoThank you, that was very informative. I do remember that Python had the ast module for a rules engine implementation, but I felt it was too cumbersome.. Thank you.