|
Pages: [1]
|
 |
|
Author
|
Topic: value? 'object/anything always true (Read 619 times)
|
newbie
Guest
|
I want to detect if object a has some property but it always return true:
>> a: make object! [p: 2] >> value? 'a == true >> value? 'a/p == true >> value? 'a/b == true >>
|
|
|
|
|
Logged
|
|
|
|
Guest
Guest
|
Have found a way >>find first a 'p == [p] but still would like to know if value? syntax could work somehow thanks
|
|
|
|
|
Logged
|
|
|
|
|
CarlRead
|
VALUE? isn't testing if a word exists, but whether it's set. ie, if it references a value...
>> value? 'a == false >> a: 10 == 10 >> value? 'a == true >> b: [c] == [c] >> value? 'b == true >> value? 'b/1 ; Not looking within B - the /1 is meaningless, I think. == true >> value? b/1 ; This time it's actually looking at C. == false >> c: 2 == 2 >> value? b/1 == true
Your FIND is a good way to see if a word is in a block (without other blocks within it), but in an object they may be buried within other objects or functions or whatever, so it's not a universal test.
|
|
|
|
|
Logged
|
- Carl Read
|
|
|
|
Gabriele
|
>> a: make object! [p: 2] >> found? in a 'p == true >> found? in a 'b == false
|
|
|
|
|
Logged
|
|
|
|
newbie
Guest
|
Hi thanks for this case !
Now got a similar case :
If I have a local variable b inside a function a, I can't use value? 'b to detect a global variable b:
b: 1 a: func[][ b: 5 value? 'b ] a unset 'b a
>> b: 1 == 1 >> a: func[][ [ b: 5 [ value? 'b [ ] >> a == true >> unset 'b >> a == true >>
|
|
|
|
|
Logged
|
|
|
|
newbie
Guest
|
I tried unset? 'b and it doesn't give true like I would like
>> find first rebol/words 'b == [b r modulo round n scale m even half-ceiling floor ceiling found? half-down down component? boot-list queue-boot priority repen... >> b ** Script Error: b has no value ** Near: b >> unset? 'b == false >>
|
|
|
|
|
Logged
|
|
|
|
|
Gabriele
|
UNSET? is not the opposite of VALUE?.
value? word basically means not unset? get/any word; unset? word will always return false.
About your problem with checking a global word when you also have it global, just use value? in system/words 'b to check if 'B has a value in the global context.
|
|
|
|
« Last Edit: October 15, 2005, 06:08:01 AM by Gabriele »
|
Logged
|
|
|
|
|
Sunanda
|
As you are looking for words in an object, I think this does what you want:
a: make object! [p: 2] get in a 'p == 2 get in a 'q == none
Just bear in mind that in some still-current versions of REBOL, you get an error for that:
get in a 'q ** Script Error: get expected word argument of type: any-word ** Near: get in a 'q
So to cover all recent cases, you may need to wrap the test in an attempt.
|
|
|
|
|
Logged
|
|
|
|
|
|
Pages: [1]
|
|
|
 |
News: 01-09-08 Alpha version of REBOL 3 has been released!
2315 Posts in 597 Topics by 4204 Members
Latest Member: hledamka.com
|