A Sneak Peek at MetaCat

MetaCat is a term rewriting macro language for Cat, in other words it is Cat + macros. It can be used to describe the operational semantics of the primitive functions, but its primary role (at least for now) is for expressing optimization strategies.  The MetaCat macros were inspired by Manfred von Thun’s rewriting system for Joy.

The CVS revision #175 now has working new macro functionality (enabled by calling #oz on a quotation), but the graphics and recursive function are temporarily disabled due to other improvements to the code base. It may take another week for the official release of version 0.13.0.

Anyway, here is a sneak peak of how the macros in MetaCat are defined:

// No-op reductions
macro { noop } => { }
macro { id } => { }
macro { swap swap } => { }
macro { dup pop } => { }
macro { not not } => { }
macro { pair unpair } => { }
macro { cons uncons } => { }
macro { qv eval } => { }

// Simple optimizations
macro { dup swap } => { dup }
macro { dup eq } => { pop true }

// Identities
macro { $b $a swap } => { $a $b }
macro { $a pop } => { }
macro { $b [$A] dip } => { $A $b }
macro { true [$B] [$A] if } => { $B }
macro { false [$B] [$A] if } => { $A }
macro { [$A] eval } => { $A }
macro { $a qv } => { [$a] }
macro { [$B] [$A] compose } => { [$B $A] }

// Boolean primitives
macro { true not } => { false }
macro { false not } => { true }
macro { true and } => { }
macro { false and } => { pop false }
macro { true or } => { pop true }
macro { false or } => { }

// Reduction based on the property of commutativity
macro { swap and } => { and }
macro { swap or } => { or }
macro { swap add_int } => { add_int }
macro { swap mul_int } => { add_int }
macro { swap add_byte } => { add_byte }
macro { swap mul_byte } => { add_byte }
macro { swap add_dbl } => { add_dbl }
macro { swap mul_dbl } => { add_dbl }

// Short-circuit boolean evaluation
macro { and $a and } => { and [$a] [false] if }
macro { or $a or } => { or [true] [$a] if }

Leave a Reply

You must be logged in to post a comment.