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

John Nowak <[email protected]>
Newsgroups gmane.comp.lang.concatenative
Message-ID <[email protected]>
On Feb 22, 2008, at 10:12 AM, John Cowan wrote:

> 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.

Very interesting. Unfortunately, I think the system I proposed would  
not actually bring me so close to Q. In particular, all of the  
rewriting would need be done before execution begins. This would mean  
that doing things like 'X sqr = X X *' would work, but only when 'X'  
is known at compile time because it is a literal or perhaps due to  
some partial evaluation phase. Something like '5 sqr' would translate  
to '5 5 *', but '2 3 + sqr' wouldn't work. Well, perhaps it could  
actually, as the stack effect of '2 3 +' is known at compile time. Hm.

Alternatively, it would be interesting to allow such things to happen  
at runtime, but I'm not yet sure how to go about integrating that with  
the type system. I'll have to think more about this. Perhaps it is  
just as simple as translating the rewrite rule to a function with  
locals which is then translated to a normal pointfree function. Think  
*very* quickly here as I head out the door to work...

Thanks John.

- Other John
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.