6

Is there an equivalent to forget word of Forth in Gforth?

I've seen about marker, but it doesn't have the same behaviour. Also the list command doesn't seem to give a listing of the program.

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Krackout
  • 282
  • 4
  • 14
  • Apparently `list` in original Forth listed disk blocks, not in memory program. Still, if anybody knows something equivalent to BASIC's list, it would be helpful. – Krackout Jun 25 '20 at 16:01
  • Please consider [accepting an answer](https://stackoverflow.com/help/someone-answers), if any of the answers solved your question. – mihai Jul 22 '20 at 07:05
  • Currently no answer fully solves my question. Yet I've marked as useful the ones that helped me. – Krackout Jul 22 '20 at 08:02

3 Answers3

4

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>.

This word is obsolescent and is included as a concession to existing implementations.

forth-standard.org/standard/tools/FORGET

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • _obsolete_ instead of _obsolescent_. Do you have a source for this? – mihai Jul 21 '20 at 15:40
  • see: https://forth-standard.org/standard/tools/FORGET "This word is obsolescent and is included as a concession to existing implementations." in other words it is still used but is on its way out. – Glassman2004 Jul 22 '20 at 18:21
  • Great! I've added the link and quote to your answer! – mihai Jul 23 '20 at 06:03
3

It seems to me like MARKER does the same thing as 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. 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, like the interpreter, searches starting from the back; 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.

FORGET is a good word to know; 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.)

Some Forths do not have FORGET. In that case you need to plan the forgetting in advance, e.g.:

MARKER -work

defines the null definition -work to mark the current system state for you. When you execute -work at some later time, the system state is restored to that in effect when -work was defined. In particular, all words defined after the marker word -work are completely removed from the dictionary.

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
mihai
  • 4,592
  • 3
  • 29
  • 42
1

I don't know Gforth, but FORGET based on an old FIG Forth listing is shown below. 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. This crashed (VFX) Forth when I ran it, but it may point somebody in the right direction.

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Tls Chris
  • 3,564
  • 1
  • 9
  • 24