Logiweb(TM)

7.12.1 Simple macros

Prev Up Next Page 231 of 800 Search internet


The definition

macro define value define x as y end define as define value of root protect x end protect as y end define end define

defines value define x as y end define as shorthand for define value of root protect x end protect as y end define.

As a consequence, if you write e.g.

value define x factorial as if x = 0 then 1 else x * ( x - 1 ) factorial end define

then that will macro expand to

define value of root protect x factorial end protect as if x = 0 then 1 else x * ( x - 1 ) factorial end define

which in turn macro expands to

define value of x factorial as if x = 0 then 1 else x * ( x - 1 ) factorial end define

which in turn defines the value aspect of the factorial function.

The root protect x end protect construct is for feinschmeckers; it disappears during macro expansion but guarantees that the principal operator of the term x is not macro expanded. The protection is only needed when one gives both a macro and a value definition for the same term.

The macro define x as y end define construct is easy to use but of limited power. It just cause the left hand side to be replaced by the right hand side.

The base page macro defines parentheses thus:

macro define ( x ) as x end define

Thus, parentheses disappear during macro expansion (unless protected by some other macro construct like root protect x end protect).

Macro expansion occurs inside Gödel brackets. As an example,

quote ( x + y ) + z end quote t= quote x + y + z end quote

is true because the parenthesis disappears during macro expansion in the first bracket and because the preassociativity of plus ensures that the term in the second bracket ends up having the same structure as the term in the first bracket.

Prev Up Next Page 231 of 800 Search logiweb.eu

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