Gforth conditional expression with variables - onl

2019-05-31 17:10发布

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?

标签: forth gforth
1条回答
ゆ 、 Hurt°
2楼-- · 2019-05-31 17:40

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 > .
查看更多
登录 后发表回答