In Fort, what happens if I call DOES> twice?

John Hayes ANS Forth test suite contains tests that look like this:

: WEIRD: CREATE DOES> 1 + DOES> 2 + ; WEIRD: W1 W1 

I rather do not understand what exactly this should do. The ANS Forth Specification at DOES> is largely impervious.

From reading the test case, it looks like he expects the first DOES> call to change W1 , but then the W1 call activates the second DOES> . I assume the second one is working on a word defined by the most recent call to CREATE , but that was DOES> ified already, so I'm not sure what this should do.

gforth passes the test suite, so the tests seem valid; but my favorite Forth interpreter doesn’t, and I need to figure out how to make it work ...

+5
source share
1 answer

The second DOES> call also modifies W1 .

WEIRD: creates W1 with a runtime of 1 + DOES> 2 + . The first call to W1 sets the runtime to 2 + .

This is more obvious if you changed the code for printing, for example.

 : weird: create does> drop ." ONE" does> drop ." TWO" ; ok weird: w1 ok w1 ONE ok w1 TWO ok w1 TWO ok w1 TWO ok 

The explanation for this is that DOES> always works with the last defined word.

+5
source

All Articles