Working With Truthy BLANK!

The current re-imagining of the concept of truthy/falsey involves the idea that anything you can put into a block is truthy. That includes BLANK!.

~null~ isotopes are falsey, and will REIFY to be ~null~ which can be somewhat clumsy-looking.

But consider some test cases for seeing how SPLIT-PATH works, looking a bit like this:

split-path-tests:  [
    %foo                            [_ %foo]
    %/c/test/test2                  [%/c/test/ %test2]
    %/c/test                        [%/c/ %test]
    %//test                         [%// %test]
    %/test                          [%/ %test]
    %//                             [%/ %/]
    %.                              [%./ _]
    %./                             [%./ _]
    %./.                            [%./ %./]
    <...etc...>
]

SPLIT-PATH is a multi-return routine, which gives back two values: the path and the filename. But if one or the other is missing then that component will be null, which is useful for testing with IF (or using DEFAULT with).

But if we just blindly changed the tests to reify, it would become less legible:

split-path-tests:  [
    %foo                            [~null~ %foo]
    %/c/test/test2                  [%/c/test/ %test2]
    %/c/test                        [%/c/ %test]
    %//test                         [%// %test]
    %/test                          [%/ %test]
    %//                             [%/ %/]
    %.                              [%./ ~null~]
    %./                             [%./ ~null~]
    %./.                            [%./ %./]
    <...etc...>
]

However...with blanks being truthy, this means you that you can take a variable which may be null and turn it into a blank, like this:

reduce [any [path _] any [file _]]

That's rather succinct! Probably so succinct that it doesn't need its own native to express.

(I thought it was neat.)

1 Like