| Joe Marshall 2005-11-04, 3:57 am |
| Andre <andre@het.brown.edu> writes:
> I just meant that there are many ways of implementing a
> do-until construct, many of which do not require the thunks needed
> by the one HOF example (which imply the use of side effects, as you
> observe), or the monadic types used in the other HOF example.
>
> A macro can be used to hide this detail, and can be justified by the
> same arguments used for any other kind of abstraction.
>
> These include:
>
> - Modularity: being able to change the implementation
> from e.g., thunks to monads without having to change all the use sites.
> - Optimization: The macro might construct thunks behind the
> scenes, but does not have to. A syntax that is agnostic with
> respect to this detail is arguably better than a HOF that isn't,
> for a looping construct where performance might be important.
I follow your argument, but I don't think it is compelling.
Regardless of how the construct is implemented, it is going to be the
case that the code within the construct is not going to be evaluated
in the standard manner. The user is going to have to be aware of this
one way or another.
I find explicit thunks to be a reasonable way to deal with this. They
restore the code to the standard evaluation model (at the expense of
introducing lexical closures), and the `thunk' syntax is easily and
obviously recognizable.
That said, I also think that macros are a fine tool and the fact that
some people may abuse them is not a good reason to avoid them.
|