在Forth中,“期望”读取了多少个字符?

时间:2015-07-14 20:38:56

标签: forth

Forth-83 spec定义单词expect,如下所示:

      EXPECT       addr +n --                    M,83                 
           Receive characters and store each into memory.  The transfer
           begins at addr proceeding towards higher addresses one byte
           per character until either a "return" is received or until
           +n characters have been transferred.  No more than +n
           characters will be stored.  The "return" is not stored into
           memory.  No characters are received or transferred if +n is
           zero.  All characters actually received and stored into
           memory will be displayed, with the "return" displaying as a
           space.

因此,它会读取但不包括RETURN或EOL。

但是如果没有终止符,并且没有返回读取的字符数,我怎么知道字符串的结束位置?

Leo Brodie引用了一个单词accept,它有一些非常相似的东西,它有一个签名( addr +n -- +m )。这确实会返回读取的字符数,这正是我所期望的。但那不符合规范......

1 个答案:

答案 0 :(得分:2)

standard还定义SPAN,它会告诉您读取的字符数。

另请注意,在新标准中,此功能已过时,请改用ACCEPT