We show that the 'for' operator of Python quite unexpectedly
can be represented by a 'let' form of Scheme.
Another cool example from Oleg. This time, not only a nice example of Scheme macros, but of shift/reset operators as well.
Allow me to draw the following diagram:
list-comprehensions === monads === shift/reset === range
The first two are truly equivalences: in Haskell, a list comprehension
is just another form of the 'do' notation in the case of a List monad.
Filinski showed that shift/reset can be used to implement monads in
the general way. My 'range' is based on shift-and-reset.
There is a difference however. If we avoid nested loops, then my
shift/reset (called bshift/breset) are the same as shift/reset. Alas,
regular shift/reset cannot nest. There are multi-level shift/reset,
but they are difficult to use -- and hard to encapsulate in a macro
such as 'range' because the macro needs to know on which level it
operates. My bshift/breset are different. bshift/breset with different
labels are unaware of each other.
BTW, other control operators, e.g., those by Matthias Felleisen, do
not have the indifference property. The operator 'cupto' has -- but to
some extent. Several cupto operators have to be used in a stack-wise
fashion. Mines don't have to.
Posted to functional by Ehud Lamm on 2/23/04; 1:35:53 AM
|