TO

Interpretation:

( i * x "<spaces>name" -- )

Skip leading spaces and parse name delimited by a space. Perform the "TO name run-time" semantics given in the definition for the defining word of name. An ambiguous condition exists if name was not defined by a word with "TO name run-time" semantics.

Compilation:

( "<spaces>name" -- )

Skip leading spaces and parse name delimited by a space. Append the "TO name run-time" semantics given in the definition for the defining word of name to the current definition. An ambiguous condition exists if name was not defined by a word with "TO name run-time" semantics.

Note:

An ambiguous condition exists if any of POSTPONE, [COMPILE], ' or ['] are applied to TO.

See:

Rationale:

Typical use: x TO name

Some implementations of TO do not parse; instead they set a mode flag that is tested by the subsequent execution of name. Standard programs must use TO as if it parses. Therefore TO and name must be contiguous and on the same line in the source text.

Testing:

ContributeContributions

ruvavatar of ruv Should TO be findable?Request for clarification2018-09-22 09:05:37

Since "an ambiguous condition exists if any of POSTPONE, [COMPILE], ' or ['] are applied to TO", does ambiguous condition exist if [DEFINED] is applied to TO ?

May a standard programme get xt of TO via SEARCH-WORDLIST? If yes, what semantics should this xt bring?

May TO word be absent in FORTH-WORDLIST in a standard Forth system that actually supports TO something?

AntonErtlavatar of AntonErtl 2018-09-23 06:23:10

No ambiguous condition has been specified for [DEFINED] TO, and given that it does not return an xt, I don't see a reason for it.

Yes, a system can get an xt for TO through SEARCH-WORDLIST or FIND. For FIND, the specification is quite fuzzy about the returned xt (and see the proposal on clarifying FIND for that), for SEARCH-WORDLIST it isn't. Gforth therefore returns the xt corresponding to interpretation semantics from SEARCH-WORDLIST (and nobody has complained about that).

FORTH-WORDLIST is specified as containing all implemented standard words, and that includes TO.

StephenPelcavatar of StephenPelc 2018-10-08 10:55:50

POSTPONE [COMPILE] and so on are ambiguous with respect to TO because it is unspecified how TO is implemented and how it works, e.g. it probably parses, but doesn't have to. In other words, even if you got an XT back, you would not know what to do with it, hence the code is not portable. [DEFINED] just wants to know if the word exists in the dictionary, so it only needs to return a flag.

Note that most systems permit ' ['] and so on to return an xt for any word in the system. At least one fails if the action of that xt is undefined by the standard.

Reply