1

表示如下输入的正确样式是什么,例如 Gforth 中的输入?

while (2 > 1) {1 + 1}

以我目前对网上资源的理解,应该是:

: loop begin 2 @ 1 > while 1 1 + repeat

但是,当我尝试用 Gforth 解释这一点时,我得到一个错误:

 expected dest, do-dest or scope
 : >>>loop<<< begin 2 @ 1 > while 1 1 + repeat
4

1 回答 1

3

您发布的代码有四个问题:

  • 你重新定义loop了别的东西。也许更好地命名它的其他东西。
  • 我没有看到;结束冒号定义。
  • 您使用@不是地址的东西。只是下降@2 1 >将返回真。
  • 1 1 +将结果推送到堆栈,但您不使用它。因此堆栈会溢出。

我建议这样做:

: infinite   begin 2 1 > while 1 1 + drop repeat ;

这几乎正​​是 ruvim 在评论中发布的内容。

于 2018-03-01T07:03:00.290 回答