Re: [stack] Properties of Concatenative langauges and Forth

John Nowak <[email protected]>
Newsgroups gmane.comp.lang.concatenative
Message-ID <[email protected]>
On Jan 2, 2009, at 10:20 PM, John Cowan wrote:

> Christopher Diggins scripsit:
>
>> Talking about data-flow in the context of Joy is incorrect. A Joy
>> program has no data, only functions. You'll see what I mean below.
>
> Well, sort of.  5 is a number in Joy, even if it's a function too.
> As a function, it can be applied to the stack; but if it's on the  
> stack,
> it can be added to another number by the function +.

The fantastic thing about concatenative languages is that you can  
think about it both ways.

Joy programs have data. If I take a Joy program and start it by  
passing it an empty stack, the stack that goes from function to  
function afterwards is the data.

At the same time, they have no visible objects. The syntax doesn't  
allow me to write an object. If I define 'foo' to be '5', 'foo' is  
still a function (with type R -> R Int). If I have the expression '1 2  
+' and reduce it to '3', I still have a function.

If there was an argument that concatenative languages must be stack  
based (or similar), you could base it on this point. A function that  
contains only functions which push elements onto the stack (e.g. '1 2  
3') "looks the same" as a stack itself. I can think of '1 2 +' as  
either "applying" the '+' operation to the stack '1 2' or composing  
the functions '1 2' and '+'.

This is a duality you'd lose if you passed around a dictionary instead  
of a stack. I think that's a significant consequence. There are other  
data structures where I can see how have the same duality, but they  
are all ordered (tuples, lists, more-style vectors, etc). Are there  
others?

Hm. I should probably add this duality do the "properties" section of  
the article...

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