[stack] Re: stOck
"Justin Pombrio" <[email protected]>
| Newsgroups | gmane.comp.lang.concatenative |
|---|---|
| Message-ID | <[email protected]> |
--- In [email protected], spir <denis.spir@...> wrote: > > [Sean: thought you may be interested.] > > Hello concatenators, > > I would like to exchange about possible drawbacks of a data stack and a weird idea on a possible replacement. Maybe all of this is not new, sorry if ever, but I could not find references. > > I am fully aware that stack juggling often seems mentally difficult basically because we are not used to it. If we had learnt arithmetics with postfix syntax then probably (1+2*3) would read alien. This point is not part of the issues discussed here. Instead, I think that: > > * Naming, when carefully done, is an invaluable help to clarity. > * Stack operations (swap, dup...) do not mean anything about the mental 'model'. > > About the latter remark: I think that a good program is one that mirrors the 'model' it expresses. Stack operations do not map to anything in the model (about the problem); instead they are only needed because of the stack limitations as a data structure. In other words, the choice of a stack to pass data from func to func introduces low-level code -- as opposed to high-level languages. Without any advantage of low-level languages, I guess (for instance _this_ does not help programming closer to the machine). > > Let us imagine a "stOck" instead of a stack ;-); that could be a hash/map/dict, meaning that items are named. Then we get the following advantages: > * naming > * no stack juggling > * no dup > > For illustration, say we want to compute > c * (a+b) / (a-b) > > :result (c b a -- result) + a b - / * > > or using only names > :result (c b a -- result) a b + a b - / c * > > Denis > ------ > la vita e estrany > I would like to point out that you can implement lexical scoping in a stack-based concatenative language without any great difficulty. First convert the 'let' expression into an expression using lambdas: :result (c b a -- result) a b + a b - / c * \c \b \a a b + a b - / c * Then convert this into stack-based code as shown in http://tunes.org/~iepos/joy.html#lambda. Also, I think John Nowak is right; you really do want lexical, not dynamic, scoping. Justin