>Python on the other hand has no macros I challenge this. I won't pretend that Python has full macro equivalence, but decorators are damned close.
Decorators are ways to wrap function definitions with code that gets executed at the time the function is defined. Commonly they add stuff that happens every time the function is called. This is certainly something you can do with macros, but it's not even really close to the full semantics. Macros allow you to add new special forms to the language. If Python had macros, for example, the new `with` statements would h…
Indeed decorators are a patch to a shortcoming in Python's ability to define anonymous functions or classes. If you could just say something like:
f = memoized(lambda x, y:
... some multiline function)
or C = coords_or_vectors(class:
... some class definition)
you wouldn't need the kludge: @memoized
def f(x, y):
...
@coords_or_vectors
class C:
...
Note that I'm not arguing for the syntax in the first two examples, just the ability to do the equivalent without special cases in the normal syntax of the language.In Scheme you wouldn't need to learn the extra syntax, learn and remember the order in which decorators apply (top to bottom?, inner to outer?).
I was actually very happy when decorators got added to Python. But let's face it, they just give you a way out of a corner Python painted itself into. They're nothing to be too proud of.