Re: [stack] possibilities for macros in a typed language

John Cowan <[email protected]>
Newsgroups gmane.comp.lang.concatenative
Message-ID <[email protected]>
John Nowak scripsit:

> But why stop there? What if we allow rewrite rules along the lines of  
> MetaCat as normal definitions? Even though we can't define 'm = dup  
> i', we could define '$a m = $a $a i'. Optimizations like 'swap swap =  
> ' could sit aside normal definitions.
> 
> I feel like I'm probably reinventing something here. Are there any  
> existing languages that work like this?

You are getting very close to Q <http://q-lang.sourceforge.net>.
Q is a functional programming language based directly on equational
reasoning, rather than using it as sugar for lambda expressions only.
(It is eager and dynamically typed.)  Here's my favorite toy example,
for putting Boolean expressions, possibly including variables, into
disjunctive normal form (constants are lowercase, variables uppercase,
"and" and "or" have already been declared infix):

// eliminate double negations:
not not A               = A;

// push negations inward (de Morgan's laws):
not (A or B)            = not A and not B;
not (A and B)           = not A or not B;

// distributivity laws:
A and (B or C)          = A and B or A and C;
(A or B) and C          = A and C or B and C;

// associativity laws:
A and (B and C)         = (A and B) and C;
A or (B or C)           = (A or B) or C;

Note that there is nothing resembling constructor discipline!

-- 
Where the wombat has walked,            John Cowan <[email protected]>
it will inevitably walk again.          http://www.ccil.org/~cowan
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.