Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: value? 'object/anything always true
Pages: [1] Print
Author Topic: value? 'object/anything always true  (Read 620 times)
newbie
Guest


Email
value? 'object/anything always true
« on: October 10, 2005, 09:14:23 AM »

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


Email
value? 'object/anything always true
« Reply #1 on: October 10, 2005, 09:19:57 AM »

Have found a way
>>find first a 'p
== [p]

but still would like to know if value? syntax could work somehow thanks Smiley
Logged
CarlRead
Full Member
***
Offline Offline

Posts: 105


View Profile
value? 'object/anything always true
« Reply #2 on: October 10, 2005, 03:28:47 PM »

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
Full Member
***
Offline Offline

Posts: 182


View Profile WWW
value? 'object/anything always true
« Reply #3 on: October 11, 2005, 05:13:57 AM »

Code:
>> a: make object! [p: 2]
>> found? in a 'p
== true
>> found? in a 'b
== false
Logged
newbie
Guest


Email
value? 'object/anything always true
« Reply #4 on: October 14, 2005, 07:15:46 AM »

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


Email
value? 'object/anything always true
« Reply #5 on: October 14, 2005, 07:27:59 AM »

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
Full Member
***
Offline Offline

Posts: 182


View Profile WWW
value? 'object/anything always true
« Reply #6 on: October 15, 2005, 06:06:53 AM »

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
Full Member
***
Offline Offline

Posts: 113


View Profile
value? 'object/anything always true
« Reply #7 on: October 15, 2005, 03:43:44 PM »

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] Print 
Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: value? 'object/anything always true
Jump to:  

  
Quick Search...

Advanced search
  
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 03, 2008, 10:14:07 PM
Username: Password: Session Length:
  

News: 01-09-08

Alpha version of REBOL 3 has been released!


  
2315 Posts in 597 Topics by 4205 Members
Latest Member: TimTearton

  Rebol Talk Forum | Powered by SMF 1.0.9.
© 2001-2005, Lewis Media. All Rights Reserved.

RT design by Defiant Pc