Path Access Problem
[1/3] from: rsnell::webtrends::com at: 16-Nov-2000 10:40
When I access a value in a block via a path, the
value seems right but the type does not.
>> m: [b false]
== [b false]
>> probe m/b
false
== false
Looks ok so far, BUT
>> type? m/b
== word!
which means that things like this don't work:
>> if m/b [print "what?"]
what?
>>
Is there a way to make this work?
(BTW, Thanks Larry for that last 'any 'all trick)
TIA,
Rodney
[2/3] from: joel:neely:fedex at: 16-Nov-2000 13:11
Hi, Rodney,
This is another interesting REBOL-ism that just has to be learned.
[rebol-bounce--rebol--com] wrote:
> When I access a value in a block via a path, the
> value seems right but the type does not.
<<quoted lines omitted: 11>>
> >>
> Is there a way to make this work?
The type and value are both right, you just have to redefine the
meaning of "right" ;-) Seriously, take a look at this
>> m: [b false]
== [b false]
>> foreach item m [print [item type? item]]
b word
false word
The value of m is a block that just contains two words. However,
'false is a word whose value is preset to the logic! value of untrue
(also the value of words spelled "no" and "off").
To get the behavior you're wanting, you need to initialize your block
to associate the word b with the logic value of false. For example:
>> m: reduce ['b false]
== [b false]
>> either m/b [print "Yup!"] [print "Nope!"]
Nope!
or
>> m: reduce ['b 1 < 2]
== [b true]
>> either m/b [print "Yup!"] [print "Nope!"]
Yup!
>> m: [b none]
== [b none]
>> m/b: 0 = 1
== [b false]
>> either m/b [print "Yup!"] [print "Nope!"]
Nope!
Remember, REBOL is a *very* "literal-minded" language! ;-)
-jn-
--
; Joel Neely [joel--neely--fedex--com] 901-263-4460 38017/HKA/9677
REBOL [] foreach [order string] sort/skip reduce [ true "!"
false head reverse "rekcah" none "REBOL " prin "Just " "another "
] 2 [prin string] print ""
[3/3] from: larry:ecotope at: 16-Nov-2000 11:45
Hi Rodney
Joel has provided the explanation of your example. But there is a quick way
to force the conversion of the word "false" to the logic value "false". Just
use DO like this:
>> type? do m/b
== logic!
>> if not do m/b [print "it's false"]
it's false
HTH
-Larry
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted