5 ms·
Ah, interesting, I wish the title had been prefixed with "What if ". There's a language where THEN basically means ENDIF... Forth, if memory serves me right?
by BruceEel 6y ago
Ah, interesting, I wish the title had been prefixed with "What if ".
There's a language where THEN basically means ENDIF... Forth, if memory serves me right?
- morelisp 6y agoYes, Forth is stack-based RPN so "IF" naturally comes after the test; "THEN" marks the end of the block; so if you want "ELSE" it ends up in the middle to let you nest conditions. : /CHECK DUP 0= IF ." invalid " DROP ELSE / THEN ; https://www.forth.com/starting-forth/4-conditional-if-then-statements/ https://www.forth.com/starting-forth/4-conditional-if-then-s...
- lebuffon 6y agoYes. It is used in the sense of the English statement: IF you go to the store get some butter THEN come right back. So THEN is where the program continues on a false condition. Typically Forth. It uses an alternative way of looking at things.
- MaxBarraclough 6y agoThe GForth documentation addresses this. [0] Forth is simply adopting a different use of 'then' than the one more commonly seen in programming languages, but it's still faithful to English. [0] https://gforth.org/manual/Selection.html https://gforth.org/manual/Selection.html See also the StackOverflow thread on this topic: https://stackoverflow.com/q/12539634/ https://stackoverflow.com/q/12539634/
- astrobe_ 6y agoYes, and the inventor of the language eventually removed ELSE from his dialects, amusingly. These days he says that his code has very few conditional statements. I think the tactic strategy to achieve this is to confine conditional branches in a few well chosen words. For instance if you have a word SORT that sorts the top pair on the stack, which has to have a branch: : SORT 2DUP < IF SWAP THEN ; then you can build "if-less" MIN, MAX and ABS: : MIN SORT NIP ; : MAX SORT DROP ; : ABS 0 SORT SWAP - ;
- BruceEel 6y agoDespite my somewhat crippled ability to think RPN, I love the simplicity and expressiveness of the above.