- ABORT
- ABORT"
- ABS
- ACCEPT
- ACTION-OF
- AGAIN
- ALIGN
- ALIGNED
- ALLOT
- AND
- BASE
- BEGIN
- BL
- BUFFER:
- [
- [CHAR]
- [COMPILE]
- [']
- CASE
- C,
- CELL+
- CELLS
- C@
- CHAR
- CHAR+
- CHARS
- COMPILE,
- CONSTANT
- COUNT
- CR
- CREATE
- C!
- :
- :NONAME
- ,
- C"
- DECIMAL
- DEFER
- DEFER@
- DEFER!
- DEPTH
- DO
- DOES>
- DROP
- DUP
- /
- /MOD
- .R
- .(
- ."
- ELSE
- EMIT
- ENDCASE
- ENDOF
- ENVIRONMENT?
- ERASE
- EVALUATE
- EXECUTE
- EXIT
- =
- FALSE
- FILL
- FIND
- FM/MOD
- @
- HERE
- HEX
- HOLD
- HOLDS
- I
- IF
- IMMEDIATE
- INVERT
- IS
- J
- KEY
- LEAVE
- LITERAL
- LOOP
- LSHIFT
- MARKER
- MAX
- MIN
- MOD
- MOVE
- M*
- -
- NEGATE
- NIP
- OF
- OR
- OVER
- 1-
- 1+
- PAD
- PARSE-NAME
- PARSE
- PICK
- POSTPONE
- +
- +LOOP
- +!
- QUIT
- RECURSE
- REFILL
- REPEAT
- RESTORE-INPUT
- R@
- ROLL
- ROT
- RSHIFT
- R>
- SAVE-INPUT
- SIGN
- SM/REM
- SOURCE-ID
- SOURCE
- SPACE
- SPACES
- STATE
- SWAP
- ;
- S\"
- S"
- S>D
- !
- THEN
- TO
- TRUE
- TUCK
- TYPE
- '
- *
- */
- */MOD
- 2DROP
- 2DUP
- 2/
- 2@
- 2OVER
- 2R@
- 2R>
- 2SWAP
- 2!
- 2*
- 2>R
- U.R
- UM/MOD
- UM*
- UNLOOP
- UNTIL
- UNUSED
- U.
- U<
- U>
- VALUE
- VARIABLE
- WHILE
- WITHIN
- WORD
- XOR
- 0=
- 0<
- 0>
- 0<>
- \
- .
- <
- >
- <>
- #>
- <#
- #
- #S
- (
- ?DO
- ?DUP
- >BODY
- >IN
- >NUMBER
- >R
6.1.1345 ENVIRONMENT? environment-query CORE
c-addr is the address of a character string and u is the string's character count. u may have a value in the range from zero to an implementation-defined maximum which shall not be less than 31. The character string should contain a keyword from 3.2.6 Environmental queries or the optional word sets to be checked for correspondence with an attribute of the present environment. If the system treats the attribute as unknown, the returned flag is false; otherwise, the flag is true and the i * x returned is of the type specified in the table for the attribute queried.
See:
Rationale:
Testing:
T{ S" X:deferred" ENVIRONMENT? DUP 0= XOR INVERT -> <TRUE> }T
T{ S" X:notfound" ENVIRONMENT? DUP 0= XOR INVERT -> <FALSE> }T
ContributeContributions
AidanPitt-Brooke
[284] First testcase brokenSuggested Testcase2023-02-16 07:07:08
By my reading, the phrase DUP 0= XOR INVERT should transform the flag returned by ENVIRONMENT? into a false flag, regardless of what it started as. The first test case (querying "X:deferred") is thus guaranteed to fail.
I spent some time coming up with a testcase that I thought was sure to be useful, but then I read the specification here and at 3.2.6 Environmental queries more carefully. There appears to be nothing that prevents a standard-compliant system from simply responding false, "unknown", to all queries; the only restriction is that an attribute cannot cease to be known (and cannot change once known, if it is specified to be constant). With that in mind, ENVIRONMENT? is well and truly untestable.
JimPeterson
[425] Implementation Query?Request for clarification2026-02-20 15:44:56
Should there be a standard environmental query that returns a string specifying which Forth implementation is present? Of course, current implementations could already decide to provide such a query on their own, but guiding implementors into a standardized query could make things prettier, in general:
: which-impl
." Implementation: "
S" IMPLEMENTATION" ENVIRONMENT? 0= IF S" unknown" THEN TYPE CR
;
: is-gforth
S" IMPLEMENTATION" ENVIRONMENT? IF 6 MIN S" Gforth" COMPARE 0= IF TRUE EXIT THEN THEN FALSE
;
Or maybe it would be even better to encourage implementors to return a boolean based on "IMPLEMENTATION=<impl>" queries:
S" IMPLEMENTATION=GFORTH" ENVIRONMENT? [IF]
\ Gforth-specific stuff
[ELSE]
\ more generalized variant
[THEN]
The ability to determine the particular implementation seems very useful for optimization purposes, and ENVIRONMENT? feels like the facility in which to place such an ability.
Some implementations may already have added their own, implementation-specific queries, in which case adding more queries in the standard could have the potential for collisions. Should the standard encourage that, if an implementation adds their own specific queries that they prefix the string like "<impl>:<query>", for example: "GFORTH:NATIVE-FLOATING-POINT", and subsequently promise to never add standard queries containing a colon?