Movatterモバイル変換
[0]ホーム
Hygienic macros (was: do...until wisdom needed...)
Douglas Alannessus at mit.edu
Tue Apr 17 20:59:52 EDT 2001
"Brett g Porter" <BgPorter at NOartlogicSPAM.com> writes:> Hi -- for the non-LISP-ers among us -- could someone give a précis> on what makes a macro 'hygienic'? A quick Google search turned up> tons of links, but none that were explanatory (at least not to a> non-LISP programmer like myself), and ESR's Jargon File doesn't> cover it.Lisp has traditionally had "procedural macros". Procedural macros inLisp are a kind function -- they are implemented in Lisp, but thereturn value of the macro, rather than being returned as a functionvalue, is taken to be a piece of code. This is easier in Lisp thanin most languages because Lisp code is a kind of Lisp data structure.The code that is returned by the macro call, which is executed atcompile-time, is used to replace the original call to the macro.This allows a programmer to define new syntactic forms. These behavedifferently from normal function calls, since they can do things likerebind variables in the scope of the macro invocation, etc., and theyavoid procedure call overhead, so they can be used to effectivelyforce inlining.The problem with non-hygienic macros is that variable names used by themacro implementation can conflict with variable names that are passedinto the macro. Hygienic macros solve this problem by putting thevariables in different namespaces.Hope this helps.|>oug
More information about the Python-listmailing list
[8]ページ先頭