Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: The all function.

From: joel:neely:fedex at: 14-Apr-2002 7:42

Hi, Louis, I've had a hard time understanding the exact setting of the problem... Sorry! Dr. Louis A. Turk wrote:
> all [find database code (in database/2 'chknum) database/2/chknum] > > appears to be stopping most of the time at the first record in the > database, and returning its chknum. >
Let me make a couple of assumptions: 1) DATABASE is a series containing alternating strings (used as keys) and objects (the corresponding values). 2) Each object has a CHKNUM attribute. 3) Given a key (string) you want the corresponding CHKNUM value. I can build a trivial test case for requirements (1) and (2) by database: [] repeat i 10 [ append database join "X" i append database make object! [ chknum: i stuff: random 1000000 ] ] == ["X1" make object! [ chknum: 1 stuff: 170632 ] "X2" make object! [ chknum: 2 stuff... Under those assumptions... rec: all [obref: select database code obref/chknum] will give you back the CHKNUM field of the object associated with CODE, or NONE if there is no such key.
>> rec: all [obref: select database "X7" obref/chknum]
== 7
>> rec: all [obref: select database "XYZ" obref/chknum]
== none
>> rec: all [obref: select database "X3" obref/chknum]
== 3 If the phrase obref: select database code finds the desired key, then OBREF will refer to the corresponding object and obref/chknum will obtain the desired attribute. OTOH, if the key does not exist in the series, then OBREF will be NONE and the ALL will terminate with that value. Hope I haven't missed the point! -jn- -- ; Joel Neely joeldotneelyatfedexdotcom REBOL [] do [ do func [s] [ foreach [a b] s [prin b] ] sort/skip do function [s] [t] [ t: "" foreach [a b] s [repend t [b a]] t ] { | e s m!zauafBpcvekexEohthjJakwLrngohOqrlryRnsctdtiub} 2 ]