6.1.2216 SOURCE CORE

( -- c-addr u )

c-addr is the address of, and u is the number of characters in, the input buffer.

See:

Rationale:

SOURCE simplifies the process of directly accessing the input buffer by hiding the differences between its location for different input sources. This also gives implementors more flexibility in their implementation of buffering mechanisms for different input sources. The committee moved away from an input buffer specification consisting of a collection of individual variables.

Testing:

: GS1 S" SOURCE" 2DUP EVALUATE >R SWAP >R = R> R> = ;
T{ GS1 -> <TRUE> <TRUE> }T

: GS4 SOURCE >IN ! DROP ;
T{ GS4 123 456 
    -> }T

ContributeContributions

MitraArdronavatar of MitraArdron [172] Relationship to block setExample2020-12-27 08:43:01

Should this make clear its relationship to the BLOCK word set i.e. if BLK is set, then should SOURCE return a caddr and length of the block, or should a user test BLK before calling SOURCE ?

AntonErtlavatar of AntonErtl

Looking at LOAD, it says:

Store u in BLK (thus making block u the input source and setting the input buffer to encompass its contents)

SOURCE returns the input buffer. I am not happy with the "thus", because it implies that SOURCE checks the contents of BLK. However, because a standard program must not store into BLK by itself, a standard system can also implement LOAD in a way that affects SOURCE more directly (and SOURCE may be a 2VALUE or somesuch). But in any case, the effect of LOAD on SOURCE is clear, and a program does not need to check BLK before using SOURCE.

Closed

MitraArdronavatar of MitraArdron

I guess so - so essentially SOURCE (unless its a variable) needs to check BLK and SOURCE-ID - which can only be 0 (for normal); -1 for a string and positive for a file (according to https://forth-standard.org/standard/core/SOURCE-ID and https://forth-standard.org/standard/file/SOURCE-ID (note the latter explicitly points out ambiguity if BLK is non-zero.)

<RANT> One of the challenges I believe with the way this standard is written, is that to implement the words in the standard you have to know specific precise definitions in other words that aren't obviously linked - especially those in extension sets.

AntonErtlavatar of AntonErtl

Yes, the definition of SOURCE could benefit from adding FILE SOURCE-ID and BLK to the SEE: part.

AntonErtlavatar of AntonErtl

This comment has been answered. Closing.

Closed
Reply New Version