2

In another question, I saw the following syntax:

#[unset!]

What is that? If I say type? #[unset!] in R3, it tells me unset!, but it doesn't solve the mystery of what #[] is.

So curious.

Gregory Higley
  • 15,923
  • 9
  • 67
  • 96

4 Answers4

6

#[] is the serialized form for values. Play with MOLD versus MOLD/ALL in the console to get a feel for it.

Joe
  • 46,419
  • 33
  • 155
  • 245
Gregg Irwin
  • 151
  • 3
4

the #[] "syntax" is actually not a syntax as such (not legal syntax, if you try it), only special cases of such constructs are "legal", like the #[unset!] syntax, #[true] syntax, #[false] syntax, #[none!] syntax, or #[datatype! unset!] syntax.

What is even more interesting, is, what the #[unset!] value actually is. It happens to be the value every "uninitialized" variable in REBOL has (not in functions, though, function local variables are initialized to #[none!]), as well as the result of such expressions like print 1, do [], (), etc.

Regarding the "function local variables ... initialized to #[none!]" I should add, that only the variables following an "unused refinement" (i.e. the one not used in the actual call) are initialized to #[none!] together with the refinement variable.

To explain the issue further, the syntactic (Data exchange dialect) difference between true and #[true] is, that the former is a word, while the latter is a value of the logic! type. Seen from the semantic (Do dialect) point of view, the difference is smaller, since the (global) word is interpreted as a variable, which happens to refer to the #[true] value.

Ladislav
  • 151
  • 2
2

Looks like it's the value-construction syntax for an unset instance, as opposed to the word unset!:

>> comparison: [unset! #[unset!]]
== [unset! unset!]

>> type? first comparison
== word!

>> type? second comparison
== unset!

>> second comparison
>> first comparison
== unset!

If you're in a programmatic context you could do this with to-unset, but having a literal notation lets you dodge the reduce:

>> comparison: reduce ['unset! to-unset none]
== [unset! unset!]

>> second comparison
>> first comparison
== unset!

Looks like they've reserved the #[...] syntax for more of these kinds of constructors.

  • 1
    BTW, check out some of my nuts Rebol-vs-Perl competition in Code Golf. :) http://stackoverflow.com/questions/2527477/code-golf-connecting-the-dots/3066878#3066878 – HostileFork says dont trust SE Jun 18 '10 at 07:18
  • It's getting easier, but here's one I did last night before that dot connection one that I got burned out on and didn't feel like pushing forward to the point of "winning"... sure these can be improved, if you want to play :) http://stackoverflow.com/questions/3034331/code-golf-rotating-maze/3060396#3060396 – HostileFork says dont trust SE Jun 18 '10 at 08:47
1

Look at the example below:

trace on
>> e: none
Trace:  e: (set-word)
Trace:  none (word) ;<<<<<

>> e: #[none]
Trace:  e: (set-word)
Trace:  none (none) ;<<<<<

none is a word in the first one, but in the second one, #[none] is not a word, it is the Rebol value of the datatype none!. Similarly for other values like true, false. The #[unset!] case is special since every undefined variable actually has this value.

Ladislav
  • 970
  • 4
  • 15
endo64
  • 2,269
  • 2
  • 27
  • 34