Here is Oleg Kiselyov’s monads sampler for Scheme. The author’s preferred form relies on a deprecated form of Scheme macro, define-macro, which keeps that form from operating in modern Schemes. I prefer the new ‘hygienic’ macros, or better yet, no macros whatsoever. The author first provides a version, build-btree-r without using the define-macro mechanism. Without that macro the code runs. Evidently the value of pp is some local ‘pretty print’ routine which we do without. This collection of pure Scheme produces the reported value! Some of the bulk of the Scheme code is devoted to explanation. Some may find this slimmed down versions easier.

This describes a form of define-macro that seems unrelated to the form used in the sampler. Perhaps it was an official part of some Scheme earlier than R5RS. Notice that the letM macro defined in the sampler captures the free identifier >>= in the just way that hygienic macros were designed to prevent. Such usage makes it hard to find the applied occurrences of >>= or guard against innocently binding >>= to other values. There is a conflict of principles.

Here is a simple transcription of Kiselyov’s macros to hygienic macros that runs in MzScheme 352 and here is a compact version of same.