重新定义单词 [英] Word redefinition in Forth

查看:103
本文介绍了重新定义单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Forth中,如果重新定义单词,那么使用重新定义的单词的另一个单词的预期行为是什么? 例如如果x调用y:

In Forth, in case of re-definition of word, what is the expected behavior of another word that uses the re-defined one? For e.g. if x calls y:

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

然后在重新定义Y之后,XOld YNew Y的输出应该是什么?

then after the re-definition of Y, what should be the output of X, Old Y or New Y ?

推荐答案

简短的答案:X将输出Old Y,另请参见

The short answer: X will output Old Y, see also your example in online test. At the time when Y is defined in the second time, the X is already compiled.

在Forth中,重定义只是遮蔽:新定义的名称遮盖了同一单词列表中的另一个名称,并且被该名称遮盖的定义变得不可访问(无法找到)的情况.

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). As the result, the new definitions don't affect any previous definitions (and already compiled code).

这篇关于重新定义单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆