Re: [stack] What does "concatenative" actually mean?
John Nowak <[email protected]>
| Newsgroups | gmane.comp.lang.concatenative |
|---|---|
| Message-ID | <[email protected]> |
On Mar 3, 2009, at 4:56 AM, spir wrote:
> :plus <whatever> ;
> :plus1 1 plus ;
>
> Can we say that the code above is equivalent to:
>
> func plus(a,b)
> <whatever>
> func plus1(n)
> plus(n, 1)
I'm not sure this'll help, but I'll try.
In a stack-based concatenative language, every function takes a stack
as input and returns a new stack as a result. Accordingly, we might
implement the 'plus' function of a concatenative language in Scheme as
such:
(lambda (s) (cons (+ (car s) (cadr s)) (cddr s)))
Another example would be 'dup':
(lambda (s) (cons (car s) s))
And 'dip':
(lambda (s) (cons (cadr s) ((car s) (cddr s))))
Of course, if you're not familiar with Lisp, I've just confused you
even more.
>> Not at all. Haskell is purely functional (i.e. there are *no* side
>> effects), but not concatenative.
>
> Still unclear for me. (good, I have unknown worlds to explore ;-)
In Haskell, not all terms denote functions. In concatenative
languages, all terms denote functions. In Haskell, juxtaposition
denotes application. In concatenative languages, juxtaposition denotes
composition.
> This is something I really do not understand. In many OO languages,
> especially prototype-based ones, objects are simple map/dict like
> variables. They can be refered to from inside any word/
> func/'action'; so as I understand the point they act, at least can
> act, as global state, environment, variables that will necessarily
> break the (referential) "safety" of the function.
The object systems in Factor and Forth do break referential
transparency. If this means that are not "purely concatenative"
depends on who you ask.
- John