Also, your particular use of a decorator is similar to what "racket/trace" accomplishes. The library provides hooks for tailoring the trace to your needs.
Thanks for your suggestion! However, I'm looking for a more general decorator mechanism, rather than something specifically intended for tracing or debugging.
This is really cool; definitely one of my favourite bits of Python syntax. I cut my teeth on higher-order functions with the old snake.
This is kind of a hacky attempt which doesn't really enforce any constraints on the positioning of the decorators, and it is slightly less general perhaps in its approach to the decorator functions themselves, but I'm sure others will have brighter ideas regarding a more "Racket-ey" version of things.
p.s. Having pointed out impersonators, I have to say: Every time I've done some flavor of advice/trace/decorator/AOP ... I've either "just" used function composition, or, written the kind of sugar macro you were already discussing.
p.p.s. My guess is the history/motivation of impersonators is connected to Racket contracts. But that's just my guess and maybe there's a more interesting story.
On Mar 16, 2025, at 9:03 AM, Greg Hendershott via Racket Discourse notifications@racket.discoursemail.com questioned whether "the history/motivation of impersonators is connected to Racket contracts.”
This is indeed correct. The impetus is due to Strickland, whose dissertation goal was to expand the contract system to classes, objects, etc. Since those are mutable, we also had to figure out a story for mutable values such as vectors. One days S. came to my office to explain how our “lambda wrapping approach” (which works for first-class classes, too) just wouldn’t work out. “We need two kinds of basic wrappers that protect values: chaperones and impersonators.” — Matthew and Sam and Robby were visiting soon after, and it turned out, they had similar ideas, but unlike S. none had acted on it. Once Matthew baked this wrappers into Racket, their general applicability became clear and the contract system could finally cope with mutable values such as vectors properly.