Definition of FIND on an OBJECT

Carl Sassenrath, CTO
REBOL Technologies
6-Jun-2008 21:57 GMT

Article #0139
Main page || Index || Prior Article [0138] || Next Article [0140] || 11 Comments || Send feedback

R3 2.100.13 adds both select and find actions (datatype function methods) to the OBJECT datatype. But, we still have a decision to make and soon! Here's the situation...

Select is similar to the idiom get in. It returns the value bound to the word within the object's context:

>> obj: make object! [a: 10 b: none]
>> select obj 'a
== 10
>> select obj 'b
== none
>> select obj 'c
== none

For many years I avoided adding this usage of select, but I've recently been writing code where both the object and the selector word can optionally be NONE, and I don't want to wrap everything with extra conditional checks or all blocks. So, I caved-in and finally added it. Yell loudly if you think it's a mistake. (My inclination is that this is fine, but I'm not sure I'm as smart as I was in 2000. Maybe it is the red wine.)

The last two cases above highlight a long-standing minor issue with objects: you cannot detect the existence of a word via selection (you must use either in or the words-of function). It's not a big problem and in fact can be considered a feature because it has its uses.

However, with that in mind, find has been defined to work this way:

>> find obj 'a
== true
>> find obj 'b
== true
>> find obj 'c
== none

Here find tells you that the word is defined in the context, even though its value is NONE.

Of course, you can do roughly the same thing with the in function:

>> in obj 'b
== b
>> in obj 'c
== none

So the bigger question becomes: is there some other find feature that we may want to use on objects? For example, would it be more useful for find to search the value part of an object, as in:

>> find obj '10
== a
>> find obj "test"
== none
Must be decided now...

To avoid compatibility problems, we need to decide on this issue before the release of 2.100.14.

Please post your thoughts on this here in the comments section. Thanks.


Updated 11-Jun-2024 - Edit - Copyright REBOL Technologies -