Hi Olivier,

you wrote:

>So unset! seems to be a datatype.
>Lets verify if unset! is a datatype :
>
>>> type? file!
>== datatype!
>>> type? unset!
>** Script Error: unset! has no value.
>** Where: type? unset!

One of REBOL's most confusing issues is that representations of some values
look exactly like the words they are assigned to. These values cannot be
directly parsed by REBOL - first they are parsed to words, and then the word
is evaluated.

When you did:

>> type? file!
== datatype!

REBOL first parsed the string you typed, "file!", to the word file!, and
then when that word is used as the argument of TYPE? it is evaluated. The
word FILE! is preset to the datatype! file!, which is the value that the
function TYPE? sees.

Try this:

>> a: [type? file!]
== [type? file!]
>> type? first a
== word!
>> type? second a
== word!

While they're still in an unevaluated block, type? and file! are still
just words. But when you do (that is, evaluate) that block, the correct
answer comes out:

>> do a
== datatype!

Here's another way to look at this:

>> a: ['type? file!]
== ['type? file!]
>> type? first a
== lit-word!
>> a: reduce a
== [type? file!]
>> type? first a
== word!
>> type? second a
== datatype!

First I made a block with one lit-word! and one word! . Then when I reduced
the block, the lit-word! was evaluated to a word! , and the word file! was
evaluated to its preset value, the datatype! file! . If we do that block:

>> do a
== datatype!

we still get the same answer, because when you evaluate a datatype! you
just get the same datatype! .


Now the problem with unset! is that there is no word set to the value
unset! . This is easily fixed:

>> unset: (type?)
== unset!
>> type? unset!
== datatype!

I put the paren around type? because if you do this in a script TYPE? will
take the value of whatever is next, but the paren prevents TYPE? from seeing
anything else.


You also wrote:

>>> type? file!
>== datatype!
>>> help file!
>file! is word of value: file
>
>This not ok!

It seems inconsistent, but this is the result of a REBOL trick. HELP has a
special way of specifying its argument:

help: func [
    "Prints information about words and values."
    'word [any-type!]
    /local value args item refmode types
][
<snip>
]

The argument is specified as a lit-word! (by using the ' ). This specifies
that if the argument is actually a word, that word is to be unevaluated.
That is, HELP wants to see the word itself, not what the word is set to.
This way you can use HELP to test if a word is set to a value:

>> help grog
No information on grog (word has no value)

Otherwise, trying to evaluate the word grog would result in an error
before HELP even had a chance to see it.

So, if you want to get help on the value that the word is set to, try this:

>> help (file!)
file! is datatype
>> help file!
file! is word of value: file

Putting the word file! in a paren prevents HELP from seeing it as a word.
So the paren is evaluated, the datatype! file! comes out, and HELP
tells you that the datatype! file! is a datatype.

One other little issue here is that there are two ways of representing a
value, forming and molding. Molding is better in that it gives you a string
that REBOL can use to get back the original value, but forming is supposed
to be easier on the eye. HELP forms the values, which is why you lose
the ! 's.


See you,
Eric

Reply via email to