On 15.03.2006, at 16:55, Raphael Collet wrote:
For control structures, macros are often good enough.

I agree. Paul Graham [chap. 8, 1993] details the cases when a macro should be defined instead of a function (www.paulgraham.com/onlisptext.html). For example, control structures which potentially don't evaluate their arguments (such as 'unless') can not be defined otherwise. Alternatively, you may define 'unless' as a first-class function, but its less convenient to always wrap the consequence in a function/procedure.

One essential property of macros is that their expansion must be quite obvious. Maybe recursive macros aren't that good, after all.

For something like 'while' you could do the actual work of the control structure (such as recursive calls) in a higher-order procedure. For convenience, a macro could then call this higher-order procedure and wrap the actions in a procedure.

proc {While Cond Body}
   if {Cond} then {Body} {While Cond Body} end
end

defmacro while Cond do Body end
  {While proc {$} Cond end proc {$} Body end}
end

Best,
Torsten

--
Torsten Anders
Sonic Arts Research Centre
Queen's University Belfast (UK)
www.torsten-anders.de


_________________________________________________________________________________
mozart-users mailing list                               
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users

Reply via email to