gforth 基本执行语法

gforth base-execute syntax

一些在线 gforth 文档提供了看似 complete description of base-execute's effects:

base-execute       i*x xt u – j*x         gforth       “base-execute”

execute xt with the content of BASE being u, and restoring the
original BASE afterwards.

但是效果的语法似乎是一把没有钥匙的锁——该页面链接到任何描述 i*x xt u – j*x 含义的内容。一些狩猎出现了 partial description of the syntax notation,(它告诉我们 u 是一个 无符号数 xt 是一个 执行令牌), 但这仍然不足以理解 i*x xt u – j*x.

如何使用base-execute,它有什么作用?

要了解 base-execute 是什么,您需要了解 executeBASE。我还将解释如何在堆栈效果中读取 i*xj*x

execute 通过获取执行令牌 xt 并执行它来工作。 ' 1+ execute1+ 本身相同。但是,使用 execute 的原因是因为您可以在堆栈上传递 xt,而不必提前选择它。例如:

: exec-twice dup >r execute r> execute ;
2 ' 1+ exec-twice . ( this outputs 4 )

BASE 是一个变量,它控制用于输入和输出的数字基数。 BASE 最初是 10。所以 5 2 BASE ! . 输出 101(以 2 为基数是 5)。

base-execute 将它们放在一起:它将 BASE 更改为 u,执行 xt,然后将 BASE 恢复为其先前的值。它的实现可能如下所示:

: base-execute BASE @ >r BASE ! execute r> BASE ! ;

这是一个用法示例:

: squared ( n1 -- n2 ) dup * ;
: squares ( n -- ) 0 do i squared . loop ;

10 squares ( 0 1 4 9 16 25 36 49 64 81 )

: hex-execute ( i*x xt -- j*x ) 16 base-execute ;

10 ' squares hex-execute ( 0 1 4 9 10 19 24 31 40 51 )

10 squares ( 0 1 ... 81  we're back to decimal )

现在 i*x xt u -- j*x:

您链接到的堆栈符号文档包含阅读效果所需的大部分信息。 i*x -- j*x 意味着 某事 可能会发生在堆栈上,但它没有指定是什么。在这种情况下,确切的叠加效果取决于 xt 是什么。

要了解给定 xt 的叠加效果,请将 i*xj*x 替换为 xt 的叠加效果的两侧。

例如,如果 xt' .,您将查看 . 的叠加效果,即 n --。在那种情况下,您可以将 base-execute 的叠加效应视为 n xt-of-. u --.