简体   繁体   English

Forth 中的词重定义

[英]Word redefinition in Forth

In Forth, in case of re-definition of word, what is the expected behavior of another word that uses the re-defined one?在 Forth 中,在重新定义单词的情况下,使用重新定义的单词的另一个单词的预期行为是什么? For eg if x calls y :例如,如果x调用y

: Y ." Old Y " CR ;
: X 10 0 DO Y LOOP ;
\ ... 
: Y ." New Y " ;

then after the re-definition of Y , what should be the output of X , Old Y or New Y ?那么在重新定义YXOld YNew Y的输出应该是什么?

The short answer: X will output Old Y , see also your example in online test .简短的回答: X将输出Old Y ,另请参阅在线测试中的示例。 At the time when Y is defined in the second time, the X is already compiled.第二次定义Y的时候, X已经编译好了。

In Forth, redefinition is just shadowing: it is the case when the name of a new definition shadows some another name in the same word list, and the shadowed definition becomes inaccessible (unfindable) by this name.在 Forth 中,重新定义只是遮蔽:当一个新定义的名称遮蔽了同一个单词列表中的另一个名称时,就会出现这种情况,并且遮蔽的定义变得无法通过该名称访问(无法找到)。

Also Forth uses incremental compilation and static name resolution (that is performed in compile time). Forth 还使用增量编译和静态名称解析(在编译时执行)。 As the result, the new definitions don't affect any previous definitions (and already compiled code).因此,新定义不会影响任何以前的定义(以及已编译的代码)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM