6.1.1345 ENVIRONMENT? environment-query CORE

( c-addr u -- false | i * x true )

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.



In a Standard System that contains only the Core word set, effective use of ENVIRONMENT? requires either its use within a definition, or the use of user-supplied auxiliary definitions. The Core word set lacks both a direct method for collecting a string in interpretation state ( S" is in an optional word set) and also a means to test the returned flag in interpretation state (e.g. the optional [IF]).


\ should be the same for any query starting with X:
T{ S" X:deferred" ENVIRONMENT? DUP 0= XOR INVERT -> <TRUE>  }T


AidanPitt-Brookeavatar of 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.

AntonErtlavatar of AntonErtl

Confirmed: The X:deferred test case is wrong.

And yes, the lack of guarantees from ENVIRONMENT? means that writing discerning test cases for ENVIRONMENT? is a problem. What is possible is to write test cases that test the result if the environmental query succeeds.

Reply New Version