Logiweb(TM)

7.12.3 Basic macros

Prev Up Next Page 233 of 800 Search internet


Macros are defined by macro definitions of form

define macro of x as y end define

As an example, macro define x as y end define is macro defined by a definition like this:

define macro of macro define x as y end define as *** end define

Furthermore, macro define x as y end define macro expands into a macro definition of form

define macro of *** as *** end define

So macro define x as y end define is macro defined such that it macro expands into a macro definition.

The define macro of x as y end define construct is not at all easy to use. One pitfall is that macro expansion also occurs inside macro definitions. So one has to protect the left hand side of a macro definition against macro expansion. To see this, consider a simple macro:

macro define ( x ) as x end define

When lgc(1) loads a page, it 'reads' it several times. These 'readings' are referred to as 'first reading', 'second reading', and so on. Now consider the macro definition of parentheses above. At first reading, parentheses are not macro defined. At second reading, parentheses are macro defined such that they disappear. The macro define x as y end define construct is macro defined such that it protects its left hand side against macro expansion. But if it did not protect its left hand side, then macro define ( x ) as x end define would macro expand to macro define x as x end define. That would make x macro expand to itself, leading to an infinite loop during third reading.

Prev Up Next Page 233 of 800 Search logiweb.eu

Copyright © 2010 Klaus Grue, GRD-2010-01-05