by tom_mellior · 8y ago · 0 comments
That is, instead of:
foo doSomeThing.
bar doSomeOtherThing
you write: foo doSomeThing drop bar doSomeOtherThing
Why?It also has named variables (which some Forth purists don't like), but instead of the reasonable Smalltalk syntax of
x := baz compute: #something
it uses baz compute: #something ->x
for assignment.Why?
This might eventually turn into a nice programming language, all it needs to do is drop (haha) some of the Forth baggage and admit to itself that its Smalltalk subsystem has everything one needs.
There is a stack. You push values on the stack, then you call a function. The function takes its arguments off the stack, and pushes the return value(s) on the stack.
If you do not need the return value (which seems to be the case in your example) you ignore it by just removing it from the stack.
That's what the drop is for.
It has implemented syntax superior to Forth's by using variables and by using Smalltalk-like keyword (i.e., infix) syntax. Yes, there is a remainder of Forth-like stack syntax for expressions. It's ugly, jarring, hard to understand, and comes without any advantages since the Smalltalk-like parts require the language to use a real parser anyway!
imo you're overestimating the "smalltalk-like" part, as it is mainly word naming conventions (a ':' at the end of some words to show that something is required after) and not syntax. The "something" required after is read from the input stream as a part of the word's execution (like many Forth words).
There is no "real parser" : the parser is like any Forth parser ie one word at a time separated by blanks.
In fact, it is an Forth-like interpreter with immediate words and parsing words that use the stack structure a lot.
> There is no "real parser" : the parser is like any Forth parser ie one word at a time separated by blanks.
> In fact, it is an Forth-like interpreter with immediate words and parsing words that use the stack structure a lot.
Looking at an example like
: catalan(n) n ifZero: [ 1 ] else: [ catalan(n 1-) 2 n * 1- * 2 * n 1+ / ] ;
(from http://rosettacode.org/wiki/Catalan_numbers#Oforth) it seems like, if what you say is true, then : must be a parsing word that not only reads "catalan(n)" but also somehow decomposes it in a way and sets things up such that the later call "catalan(n 1-)" is understood correctly even though "catalan", "(", and "n" are not separated by whitespace. It very much looks like there is some tokenization going on.Also, is "ifZero:" really a separate message from "else:", i.e., or is "ifZero:" also a parsing word that looks if what follows is a well-formed expression followed by "else:"?
If you have parsing words everywhere, you have a parser. It may not be a classical parser where everything is written in one place, but it's a parser nonetheless.
I don't think there's anything wrong with implementing a Smalltalk dialect in Forth, with lots and lots of parsing words, and compiling the Smalltalk surface syntax to stack-based Forth code on the fly. That's lovely. It's just a shame to expose the underlying Forth in the surface syntax...