Gforth conditional expression with variables - only partly correct

江枫思渺然 提交于 2020-01-03 03:43:08

问题


Simple expression:

variable x  ok
4 x !  ok
3 x < . -1  ok
3 x > . 0  ok

This seems normal and correct, however:

variable x  ok
3 x !  ok
x 4 < . 0  ok
x 4 > . -1  ok

The second block of code is wrong. What is evaluating wrongly? What is the problem here?


回答1:


variable x makes a new variable, but x returns the address, not the value.

You need something like this:

variable x
3 x !  ok
x @ 4 < .
x @ 4 > .


来源:https://stackoverflow.com/questions/49040227/gforth-conditional-expression-with-variables-only-partly-correct

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!