Today marks the first release of Play, a new programming language inspired by Forth.
Play might look a lot like Forth, but improves on the languag...
For further actions, you may consider blocking this person and/or reporting abuse
Hi, I'm spending some time in having fun with Play. I have a first question (maybe a lot more after). What happens to values on stack, are they consumed after use? See e.g.
def: main
entry: true
: four-and-five +
What happens to 4 and 5 after they are summed?
It seems to me at the moment not clear how to manage values on the stack
Thanks,
m
Great to hear you're enjoying Play!
It depends on the word, really. For
+and other math words, the numbers will first be popped/consumed, then the result will be pushed onto the stack. So they're consumed as part of their use.The type of
+isInt Int -- Int. You can read that as: "consume two ints, produce one int."If you for some reason want to retain values on the stack you can use
dup(short for duplicate). So if you want to keep 4 and 5 on stack, but also the sum of them, you can do the following:four-and-five dup dup +. The resulting stack would be: 4 5 9.Many thanks for your reply!
Is there any way to see all the content of the stack at a given time and not just the last value on top of it? I am also trying to read documentation about Forth to have a clearer idea of the background, best, m
If am not wrong, please tell me, I've tried your suggestion and with rotate applied three times I got 4 10 and 5, as if the dup applied to have 2 times 5, and ten is the sum of the two. I can not explain me why, thanks again for your attention! Best, m
Unfortunetly, no. But that's definetly something that can be done in a later release!
Ahh, I was too quick in my reply and got it wrong. The following would be more correct:
Now, this is quite horrid. This is way too much stack manipulation for my taste. However, in later alpha's there will be more powerful stack manipulation words, like a specific word for doing duplicates of the two top elements on the stack.
Many thanks again for your reply. Agree with you about too much stack manipulation. Unfortunately I didn't get the same results you wrote in the comments. I'll try again to better understand if something I did was wrong. Just a last question, I was wondering to use rotate to explore the content of the stack. Does rotate work fine just with three values on the stack?
Best, m
Hot !