简体   繁体   English

与原始 Forth 中的 Gforth、FORGET 和 LIST 单词相同

[英]Gforth, FORGET and LIST words as in the original Forth

Is there an equivalent to forget word of Forth in Gforth?在 Gforth 中是否有相当于forget Forth 的词?

I've seen about marker , but it doesn't have the same behaviour.我见过marker ,但它没有相同的行为。 Also the list command doesn't seem to give a listing of the program. list命令似乎也没有给出程序的列表。

I'd like to view a list of the in-memory program, just like old list in BASIC - I think that was the behaviour in the original Forth also.我想查看内存程序的列表,就像 BASIC 中的旧list一样 - 我认为这也是原始 Forth 中的行为。

I don't know Gforth, but FORGET based on an old FIG Forth listing is shown below.我不知道 Gforth,但基于旧的 FIG Forth 列表的 FORGET 如下所示。 It is very sensitive to the dictionary layout and vocabulary organisation.它对词典布局和词汇组织非常敏感。 Words like nfa (name field address) and lfa (link field address ) have more modern equivalents. nfa(名称字段地址)和 lfa(链接字段地址)等词具有更现代的等价词。 This crashed ( VFX ) Forth when I ran it, but it may point somebody in the right direction.当我运行它时,它崩溃了( VFX ),但它可能会为某人指明正确的方向。

variable FENCE

\ Per fig forth listing ( slightly modernised )
: forget  \ "word-to-forget-from"
  CURRENT @ CONTEXT @ - ABORT" Vocabulary error."
  ' DUP FENCE @ < ABORT" Word below FENCE."
  DUP NFA DP ! LFA @ CURRENT ! ;

DP @ FENCE !

\ What was tested.  WARNING crashed Forth!!
\ My guess is that CURRENT needs to be set to a different address
: forget  \ "word-to-forget-from"
  CURRENT @ CONTEXT @ - ABORT" Vocabulary error."
  ' DUP FENCE @ < ABORT" Word below FENCE."
  >LINK DUP DP !  \ Set the top of the dictionary
  @ CURRENT ! ;   \ Point current to the last valid definition

There may be ways to leverage the implementation of marker.可能有一些方法可以利用标记的实现。 It must store a restore pointer which may be accessible to be reset to the relevant address of some definition.它必须存储一个恢复指针,该指针可以访问以重置为某些定义的相关地址。

FORGET is obsolescent and is included as a concession to existing implementations according to the Forth standard and the word you need to "list" a Forth word is SEE <word>. FORGET 已经过时,并且根据 Forth 标准作为对现有实现的让步而包含在内,您需要“列出” Forth 单词的单词是 SEE <word>。

This word is obsolescent and is included as a concession to existing implementations.这个词已经过时,并且作为对现有实现的让步而包含在内。

forth-standard.org/standard/tools/FORGET第四标准.org/standard/tools/FORGET

It seems to me like MARKER does the same thing as FORGET.在我看来,MARKER 和 FORGET 做的事情一样。 The only difference is that you need to set it up in advance.唯一的区别是您需要提前设置它。 I can confirm the behavior is as stated in Starting Forth [1] with Gforth 0.7.3.我可以确认该行为与使用 Gforth 0.7.3开始 Forth [1] 中所述相同。 Here is the excerpt:这是摘录:

The word FORGET looks up a given word in the dictionary and, in effect, removes it from the dictionary along with anything you may have defined since that word. FORGET 这个词在字典中查找一个给定的词,实际上,从字典中删除它以及从那个词之后你可能定义的任何东西。 FORGET, like the interpreter, searches starting from the back; FORGET和解释器一样,从后面开始搜索; he only removes the most recently defined versions of the word (along with any words that follow).他只删除该词的最新定义版本(以及随后的任何词)。 So now when you type GREET at the terminal, the interpreter finds the original GREET.所以现在当你在终端输入 GREET 时,解释器会找到原始的 GREET。

FORGET is a good word to know; FORGET是个好词; he helps you to weed out your dictionary so it won't overflow.他帮助你清理你的字典,这样它就不会溢出。 (The dictionary takes up memory space, so as with any other use of memory, you want to conserve it.) (字典占用了 memory 空间,因此与 memory 的任何其他用途一样,您要保存它。)

Some Forths do not have FORGET.有些 Forths 没有 FORGET。 In that case you need to plan the forgetting in advance, eg:在这种情况下,您需要提前计划遗忘,例如:

MARKER -work MARKER-工作

defines the null definition -work to mark the current system state for you.定义 null 定义 - 为您标记当前系统 state。 When you execute -work at some later time, the system state is restored to that in effect when -work was defined.当您稍后执行 -work 时,系统 state 将恢复为定义 -work 时的有效状态。 In particular, all words defined after the marker word -work are completely removed from the dictionary.特别是,在标记词 -work 之后定义的所有词都从字典中完全删除。

[1] https://www.forth.com/starting-forth/3-forth-editor-blocks-buffer/ [1] https://www.forth.com/starting-forth/3-forth-editor-blocks-buffer/

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

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