`type` 这个词有什么作用?

What does the `type` word do?

给定以下函数,(借用自Rosetta Code

: (echo) ( sock buf -- sock buf )
  begin
    cr ." waiting..."
    2dup 2dup size read-socket nip
    dup 0>
  while
    ."  got: " 2dup type ( <-- HERE )
    rot write-socket
  repeat
  drop drop drop ;

type在做什么,

."  got: " 2dup type

type is a word. You can find the list of the words here

type       c-addr u –         core       “type”

If u>0, display u characters from a string starting with the character stored at c-addr.

在这种情况下你有

128 constant size
create buf size allot

然后你用read-socket设置buftype 把它变成一个字符串并打印出来。

Returns 字符串的内存地址和大小。

cr s" foo bar " .s

输出:

<2> 94085808947584 8  ok

这里我们提供内存地址和大小给type得到“foo bar”

cr 94085808947584 8 type

输出:

foo bar  ok