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.

Why is boolean value f (false) defined as a parsing-word while t (true) is not in Factor?

+3
−0

I noticed when attempting to generate random booleans that t and f are not treated in the same way:

t random ! Error
f random ! returns a value

In the factor 0.98 and 0.99 documentation, t is defined as a simple word, whereas f is given special status as a parsing word. Why?

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

1 answer

+3
−0

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 SINGLETON: 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 and thus a sequence for which random 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.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

Sign up to answer this question »