ramidavis Posted December 17, 2017 Share Posted December 17, 2017 (edited) ... Edited January 2, 2018 by ramidavis Quote Link to comment Share on other sites More sharing options...
ramidavis Posted December 17, 2017 Author Share Posted December 17, 2017 (edited) ... Edited January 2, 2018 by ramidavis Quote Link to comment Share on other sites More sharing options...
+mizapf Posted December 17, 2017 Share Posted December 17, 2017 (edited) Forth is a stack-oriented language and uses postfix all over the place. If you order a veggie burger, don't expect beef. (I'm explicitly neutral about diet here.) Most programming languages don't formulate equations. They formulate terms for calculation, though. You (and me as well) may be familiar with infix notation, but this does not fit into the Forth concept. Edited December 17, 2017 by mizapf Quote Link to comment Share on other sites More sharing options...
Willsy Posted December 17, 2017 Share Posted December 17, 2017 Postfix notation is driving me up the walls. I am sorry, but my brain just does not see something like "4 2 3 + *" as being a valid math equation that equals 20. forth.png + adds the first 2 numbers, which are 4 and 2: 4+2=6 then * multiplies the numbers left on the stack, 3 and 6: 3*6=18 ... At least that is the way i keep seeing it in my mind. (2+3)*4 on the other hand makes perfect sense. Someone please tell me there is either: a. a way to force forth to interpret infix notation or b. a infix to postfix convertor that i can paste a math formula into and get something i can use in forth in return. This is probably my just deserts for not paying close attention in math class. I'm positive they touched on postfix, even if only briefly. But apparently it did not stick. No. + does not add the first two numbers. It adds the top two numbers. When you type 4 2 3 you have 3 at the top of the stack, 2 underneath it, and 4 at the bottom. It's a stack. Like a stack of plates. So, + removes 3 and 2 from the stack, adds them, and puts the result (5) on the stack. The stack now looks like this: 4 5 5 is at the top of the stack Then, * removes the 5 and 4, multiplies them, and puts the product on the stack. 20. You should read this. It will work with GForth. Type .s to see the stack. It's hard at first. Hang in there! 3 Quote Link to comment Share on other sites More sharing options...
Willsy Posted December 17, 2017 Share Posted December 17, 2017 (2+3)*4 on the other hand makes perfect sense. Nope. Sorry, but you're wrong. Just like "regular" in-fix, there are ways to layout the expression to make it much easier to read. And when you get the layout correct, it reads as English, and is MUCH easier to understand that in-fix with it's nested parenthesis. Your example was: 4 2 3 + * However, look what happens if you organise it like this: 2 3 + 4 * Here's how the above reads in English: Put 2 on the stack Put 3 on the stack Add them (the stack now contains 5) Put 4 on the stack Multiply them Ta dah! Simple! Quote Link to comment Share on other sites More sharing options...
ramidavis Posted December 17, 2017 Author Share Posted December 17, 2017 (edited) ... Edited January 2, 2018 by ramidavis Quote Link to comment Share on other sites More sharing options...
ramidavis Posted December 18, 2017 Author Share Posted December 18, 2017 (edited) ... Edited January 2, 2018 by ramidavis Quote Link to comment Share on other sites More sharing options...
+TheBF Posted December 18, 2017 Share Posted December 18, 2017 (edited) Forth inc.'s own swift forth does not know what to do with FORGET. Niether does yforth and gforth. Only pforth knew what to do. swift forth: : test ; ok forget test forget ? gforth: : test ; ok forget test :2: Undefined word >>>forget<<< test Backtrace: $B7170EDC throw $B717D638 no.extensions $B7171054 interpreter-notfound1 yforth: : test ; ok forget test [forget] error(2): unknown word. pforth: : test ; ok Stack<10> forget test ok Stack<10> It's sad but true, you are shooting a moving target. Forth has been going through standards changes. Forget is easy to implement in a simple system and near impossible in a complex native code system like Swiftforth. So it has been deprecated. The new word is MARKER used as below. MARKER STARTOVER Then you type STARTOVER and the system goes back to the point where the MARKER was compiled. But FORGET is part of TurboForth and FB-Forth. Edited December 18, 2017 by TheBF Quote Link to comment Share on other sites More sharing options...
+Lee Stewart Posted December 18, 2017 Share Posted December 18, 2017 Forth inc.'s own swift forth does not know what to do with FORGET. Niether does yforth and gforth. Only pforth knew what to do. FORGET is a dangerous word as you might expect. It is still in the current (2016) proposed ANS Forth standard, but is there declared obsolescent. It is in TI Forth, fbForth and TurboForth. It is probably also in CAMEL99 Forth—Brian will have to confirm. ...lee Quote Link to comment Share on other sites More sharing options...
+TheBF Posted December 18, 2017 Share Posted December 18, 2017 FORGET is a dangerous word as you might expect. It is still in the current (2016) proposed ANS Forth standard, but is there declared obsolescent. It is in TI Forth, fbForth and TurboForth. It is probably also in CAMEL99 Forth—Brian will have to confirm. ...lee I did not implement FORGET, but I should. It's still very handy for testing new code. I do miss it. Quote Link to comment Share on other sites More sharing options...
+TheBF Posted December 18, 2017 Share Posted December 18, 2017 Postfix notation is driving me up the walls. I am sorry, but my brain just does not see something like "4 2 3 + *" as being a valid math equation that equals 20. forth.png + adds the first 2 numbers, which are 4 and 2: 4+2=6 then * multiplies the numbers left on the stack, 3 and 6: 3*6=18 ... At least that is the way i keep seeing it in my mind. (2+3)*4 on the other hand makes perfect sense. Someone please tell me there is either: a. a way to force forth to interpret infix notation or b. a infix to postfix convertor that i can paste a math formula into and get something i can use in forth in return. This is probably my just deserts for not paying close attention in math class. I'm positive they touched on postfix, even if only briefly. But apparently it did not stick. I feel your pain with postfix. We have been pretty solidly brainwashed into thinking in "infix" notation after just a few years at school. Willsy has given you some excellent insights on how postfix in Forth really works. The thing that saves Forth for me is the interpreter. I type in the inputs and use the math operators and see what comes out. No compiling, no linking no waiting. When it works I give it name. It's now in the can and locked down. Once you have a named function that it is no different than calling TI-BASIC FUNCTION which is PREFIX notation. So the interpreter is your friend and making little words to do pieces of math are your friend. Quote Link to comment Share on other sites More sharing options...
+TheBF Posted December 20, 2017 Share Posted December 20, 2017 So... RamiDavis, Has your brain turned upside down yet? :-) Just wondering on your progress. Quote Link to comment Share on other sites More sharing options...
notwhoyouthink Posted December 20, 2017 Share Posted December 20, 2017 Pretty sure ramidavis has left for good. Quote Link to comment Share on other sites More sharing options...
+TheBF Posted December 21, 2017 Share Posted December 21, 2017 Pretty sure ramidavis has left for good. What makes you think so? Quote Link to comment Share on other sites More sharing options...
notwhoyouthink Posted December 21, 2017 Share Posted December 21, 2017 This thread. Looks like he got a bad attitude and called it quits. Quote Link to comment Share on other sites More sharing options...
+TheBF Posted December 21, 2017 Share Posted December 21, 2017 Unfortunate. He found the infix convertor and actually if you just test your thoughts with the interpreter it's pretty easy. 99 1 + . 100 ok It just sits there waiting for your input. How hard is that? I believe it's good for neural networks to get re-wired now and then. Keeps them healthy. I learned to play the trumpet at 57. (My mouth still hurts) Quote Link to comment Share on other sites More sharing options...
Willsy Posted December 21, 2017 Share Posted December 21, 2017 I learned to play the trumpet at 57. (My mouth still hurts) No. It's the THIN end that goes in your mouth 2 Quote Link to comment Share on other sites More sharing options...
Willsy Posted December 21, 2017 Share Posted December 21, 2017 Can't understand why anyone can't deal with postfix. All it requires is the *patience* to sit down and *learn*. It takes all of 60 seconds to understand the concept. Maybe a day or two of practice until it feels natural. I'm still in love with it. 1 Quote Link to comment Share on other sites More sharing options...
+Lee Stewart Posted December 21, 2017 Share Posted December 21, 2017 For me, the key was realizing that the stack (a LIFO, i.e., “Last In First Out”, buffer) is where all operands normally go and that words (operators) normally must deal with them as they find them on top of the stack. I say “normally” because it takes a little more work to get at items that are not on top. Even then, most words that mess with the stack order put the desired cell (16 bits or 2 bytes) on top for use. ...lee 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.