Revisiting a Maybe-Not-So-Weird Old Idea: <- as IDENTITY

Due to the change that enforces "strict mode" everywhere, you can't just write randomly into your module's global space (or script's global space, at this time scripts are isolated in the same way as modules but do new executions each time you run them and return a result that's not the module they are contained in)... you have to pre-declare things.

So this code broke:

if try first system.options.args [
    tests: local-to-file first system.options.args
] else [
    tests: %core-tests.r
]

One way to go about it would be to have a top-level declaration that you predeclare and write to it:

tests: ~
if try first system.options.args [
    tests: local-to-file first system.options.args
] else [
    tests: %core-tests.r
]

But that's a bit lame considering you could say:

tests: if try first system.options.args [
    local-to-file first system.options.args
] else [
    %core-tests.r
]

But here's where I think readability suffers a bit. Even in this short example, I feel that the fact that the result from LOCAL-TO-FILE is used isn't as obvious as it was. The longer the distance from that SET-WORD! to the expression the worse that disconnect gets.

This is why I advocated for:

tests: if try first system.options.args [
    <- local-to-file first system.options.args
] else [
    <- %core-tests.r
]

It would be completely optional. And in fact, you could make a good argument that it's not necessary on the second branch since you "know" it will be used, as it's not a function call with side-effects:

tests: if try first system.options.args [
    <- local-to-file first system.options.args
] else [
    %core-tests.r
]

Like other decisions in this medium, it's an aesthetic call, and you make the call you want.

The operator could do something I've talked about, which is be an operator that means complete fully. e.g. this could error:

tests: if try first system.options.args [
    <- local-to-file first system.options.args 10  ; FAIL: "extra stuff"
] else [
    %core-tests.r
]

So you could pick between:

foo // [arg1 arg2]
(<- foo arg1 arg2)

Eerily the same length. But, anyway, you get the idea.

It would be a little weird that -> is a function generator and <- would be the identity operator, but there is a sort of logic in terms of the direction of information flow.

I definitely consider this to be back on the table.


In the "Damn, Tripwires are Cool" Category

Here is what I did for now. :slight_smile:

tests: ~<https://forum.rebol.info/t/2165/2>~

if try first system.options.args [
    tests: local-to-file first system.options.args
] else [
    tests: %core-tests.r
]
1 Like