Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

71%
+3 −0
Q&A Why is boolean value f (false) defined as a parsing-word while t (true) is not in Factor?

The answer is indicated on the page for f. Specifically, "[t]he f object is the singleton false value, the only object that is not true." In contrast, t is defined simply as SINGLETON: t where SING...

posted 2y ago by Derek Elkins‭

Answer
#1: Initial revision by user avatar Derek Elkins‭ · 2022-08-19T01:03:33Z (over 2 years ago)
The answer is indicated on the page for [`f`](https://docs.factorcode.org/content/word-f,syntax.html). Specifically, "[t]he `f` object is the singleton false value, the only object that is not true." In contrast, [`t`](https://docs.factorcode.org/content/word-t,syntax.html) is defined simply as `SINGLETON: t` where [`SINGLETON:`](https://docs.factorcode.org/content/word-SINGLETON__colon__%2Csyntax.html) defines a class and thus a class word which is the sole instance of that class (i.e. itself).

For the purposes of logical comparisons, there is absolutely nothing special about `t`. Literally any object (other than `f`) could be used instead. As the docs say, `t` is just a "canonical" choice.

`f`, on the other hand, is uniquely special. `f` couldn't be defined the same way as `t`, i.e. as a `SINGLETON:` because then `f` and its class word would be the same thing, but the class word of `f` should be a perfectly normal object, and thus behave as true, and only its instance should behave as false.

Ultimately, the `f` object (as opposed to the `f` parsing word) is deeply wired into the Factor implementation. `t` gets some mild special handling by the implementation because the implementation needs to sometimes return `t` from the C++ implementation code. But it is not *defined* by the C++ code, while the `f` object is.

To be clear, `f` being a parsing word has nothing to do with the behavior you saw with `random`. The reason `f random` works is because `f` is an instance of an [`immutable-sequence`](https://docs.factorcode.org/content/word-immutable-sequence%2Csequences.html) and thus a [`sequence`](https://docs.factorcode.org/content/word-sequence%2Csequences.html) for which [`random`](https://docs.factorcode.org/content/word-random,random.html) is defined. `t` is not. Factor, like many languages, especially dynamically typed languages with "generalized" booleans, fails to distinguish between "no result" and "a valid result that happens to be `f`". In other words, `{ } random` and `{ f } random` both return `f` but for different reasons. `f random` is behaving more like the former as `f` behaves like an empty sequence.