4 ms·
I've never really understood stack based languages. Getting rid of variables only seems make things harder, and you always inevitably need some kind of control
by James_K 3y ago
I've never really understood stack based languages. Getting rid of variables only seems make things harder, and you always inevitably need some kind of control flow that isn't stack based (for instance the pair "[" and "]"). In this case, I suppose the advantage is that the stack is shared with C so it's easier to interact over FFI.
From what I've seen of other forths, I much prefer how this one does things. Using quoting as a sort of lambda is much nicer and more consistent than the weird compilation semantics you see in stuff like GForth.
- mananaysiempre 3y agoForth-likes are very very simple to bootstrap in basically any environment (contributing to their popularity back in the age of microcomputers sold with no OS), and once you’ve accepted the syntax are perhaps the most lightweight environments for doing DSLs (which is somewhat related, as one of the typical bootstrapping paths has you writing an assembler DSL as one of the first steps). The “postfix Lisp” PostScript/Joy/Factor heritage that TFA’s language belongs to inherits the latter property. If I had a choice of making and then using a DSL in Python, Lua, or Forth, it’s Forth all the way, no question. Now if you include Scheme, Ruby, or Tcl, then it might become a competition. (Haskell is somewhere in between.) It’s worth appreciating how much above his weight the humble granddaddy is punching here for the dozen K of memory that a running system normally takes. (Less relevant now than for the micros of old, as for interactivity that memory needs to be RAM, whereas the cheapest controllers today are usually ROM-rich and RAM-starved, relatively speaking.)
- astrobe_ 3y agoThis [] pair for quotations is pretty common in "modern" concatenative languages. But you actually don't need them that much, at least in Forth. It is not a solution because they have misidentified the problem (due to lack of experience, generally), or created a problem ex nihilo by trying to one-up Forth on RPN purity and do control-flow like Smalltalk does. a priori "must haves" that eventually get in your way. If I had to choose one quote from Chuck Moore (the creator of Forth), it would be "Don't anticipate, solve the problem you've got" [1]. What you need on a daily basis it to be able to reuse names so that you don't clutter your dictionary. But at the same time you do want your Forth to warn you when you define twice the same name, because that could lead to vicious bugs. So all you need to do is to hack your Forth so that e.g. names starting with underscores can be redefined and won't trigger a warning. [1] https://www.ultratechnology.com/1xforth.htm https://www.ultratechnology.com/1xforth.htm
- James_K 3y agoI wouldn't call people stupid just because they made a design decision you disagree with. In my view, it is a bad choice to add additional complexity to the language like compiled "if" when you can do something more simple and in-keeping with its other features. The problem isn't invented; they needed to implement conditionals, had two options for doing so, and they chose the simpler one. Do you have any concrete way that the Forth implementation with compile-only words is better? What are its benefits? > What you need on a daily basis it to be able to reuse names so that you don't clutter your dictionary. But at the same time you do want your Forth to warn you when you define twice the same name, because that could lead to vicious bugs. So all you need to do is to hack your Forth so that e.g. names starting with underscores can be redefined and won't trigger a warning. The problem is already solved. You just spit out a warning message when something is redefined instead of an error.
- astrobe_ 3y ago> I wouldn't call people stupid I don't think I did such a thing. > Do you have any concrete [proof] that the Forth implementation with compile-only words is better? What are its benefits? Yes I do : a Smalltalk-style forces to have the code (to be executed if the condition is true) to be on the left side of the if. Additionally, if you don't want the address of the quotation to be in your way, you are also forced to adopt an argument order like condition-quotation-if, which is even less convenient than Forth's syntax. Oh, and the else part could be a lot of fun too. Most likely, you'll add some sort of exception to avoid all that, but exceptions are the archetype of unwanted complexity. You seem to think that Smalltalk-style is simpler, but Smalltalk is an infix language with, granted, rules that are simpler than most other languages - but still more complex than those of Forth. So it is not, actually, simpler when you consider the system as a whole. Also, it makes it more difficult to build loops from that if and recursion like Scheme does (TCO). Chuck Moore's Colorforth does exactly that. Moreover, and perhaps more anecdotally because few people care about this these days, it is more space and CPU efficient - basically the traditional Forth if is one instruction (bytecode or whatever) followed by one parameter (the jump target) that takes one argument on the stack. A Smalltalk-style if is also one instruction, but it has to call the "if-true" code, and this code has to have a return instruction as well. I can understand that people don't care about a few more bytes and cycles here and there - what's the point for a interpreter to be able to run on a bunch of kilobytes today? - but I wonder why those same people would care about a weird RPN thing that seems to be designed to make their head hurt, with or without quotations. It's only slightly less hostile for them than BrainFuck. Computer games and computer languages have something in common: when you design and redesign them, you realize that they are a subtle network of interactions between different parts of the system - even if, in the case of programming languages you look for "orthogonality", which is the opposite; but this concept applies more to features/semantics than to syntax/ergonomics. > The problem is already solved. You just spit out a warning message when something is redefined instead of an error. You didn't get what I wrote. You want the system to keep quiet when you give an hint that you do something on purpose, like casting explicitly an integer into a pointer in C. You also miss the point: of course this problem is easily solved. But I argue like Chuck Moore that you'd rather solve the specific problem you stumble upon in practice, rather than trying to solve the more general problem that you imagine you will have. Sometimes when you try to kill two birds with one stone, you end up with one bird wounded and a broken window.
- spindle 3y ago> you always inevitably need some kind of control flow that isn't stack based (for instance the pair "[" and "]") FWIW (I don't think this answers your main complaint, but I do think it's fascinating), factor makes a lot of use of the pair "[" and "]" for control flow, but they're totally stack-based: https://docs.factorcode.org/content/word-[,syntax.html https://docs.factorcode.org/content/word-[,syntax.html https://docs.factorcode.org/content/word-%5D%2Csyntax.html https://docs.factorcode.org/content/word-%5D%2Csyntax.html