Why We Allow *Direct* Isotope Assignments (e.g. variable: ~)

"UNSET!" values were extremely ornery in historical Rebol and Red. You couldn't assign them to variables:

rebol2>> x: print "message"
message
** Script Error: x needs a value

red>> x: print "message"
message
*** Script Error: x: needs a value

In Rebol2 and R3-Alpha you couldn't test them for conditional truth or falsehood, either:

rebol2>> if print "message" [1 + 2]
message
** Script Error: if is missing its condition argument

But Red made the bizarre decision to say that "UNSET!" was truthy:

>> if print "message" [1 + 2]
message
== 3

Isotopes in Ren-C are a far more sophisticated story than UNSET!, and triggering errors in conditional slots is their raison d'etre. They guide you to finding mistakes in your reasoning:

>> value: false

>> match [integer! logic!] value
== ~false~  ; isotope

>> if match [integer! logic!] value [print "You probably want this to print!"]
** Error: ~false~ isotope is not conditionally true or false, see DID and DIDN'T

>> did match [integer! logic!] value
== #[true]  ; DID is isotope tolerant, and checks against pure NULL only

>> if did match [integer! logic!] value [print "Isotopes saved the day!"]
Isotopes saved the day!

So keeping that "ornery" behavior is important. But also important is not being ornery about assignment of QUASI! values via SET-WORD!.

It has applications everywhere...like in the round-tripping of OBJECT!s.

>> first [~]
== ~  ; ordinary QUASI! of blank (can appear in blocks, etc.)

>> ~
== ~  ; isotope (QUASI! -> isotope on evaluation)

>> make object! [u: ~, q: first [~]]
== make object! [
     u: ~
     q: '~
] 
; ^-- running this MAKE OBJECT! gets you back the isotope and BAD-WORD! correctly

But if you assign them via any evaluation (even a GROUP!) you will get an error.

>> x: print "Hi"
Hi
** Error: Cannot assign isotope with SET-WORD!, see SET/ANY

>> x: (~)
** Error: Cannot assign isotope with SET-WORD!, see SET/ANY

This seems like the best compromise to get the desired behavior.

A post was merged into an existing topic: undefined vs. null in JavaScript

2 posts were split to a new topic: Why Isn't PRINT Invisible?