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

[REBOL] Re: Multi-searches

From: brett:codeconscious at: 21-Feb-2002 20:44

Hi Philippe,
> Could you explain me this line : > while [all [not tail? series found? series: find/only series value]][
Andrew's formatting maybe have explained it for you, but if not, some more detail is below.
> I use ALL like that "all [(first test)(second test)] [consequence]" but
here
> ? and what does the rest of the line ?
First off, in case it helps, a quick correction to your example. ALL takes only one parameter, a block. The "[consequence]" part of your example is not used by ALL at all. Probably your example is part of an IF statement like this: IF condition [consequence] E.g:
>> if true [now]
== 21-Feb-2002/20:00:37+11:00
>> if all [1 2] [3]
== 3 Now on to ALL. ALL evalutes a block of expressions. If during that evaluation one of those expressions results in none! then ALL returns none!. If all the expressions are not none! then ALL returns the result of the last expression. Examples:
>> all [1 2 3 4 5]
== 5
>> all [1 2 now]
== 21-Feb-2002/19:50:44+11:00
>> all [1 2 none 4 5]
== none Back to my line. I intended this part of the line: [ not tail? series found? series: find/only series value ] to have two results. The first result is to make sure that there is something left to process. The second result is true only if the value is found in the the remaining part of the series. If either of these results in none! ALL will return none! and the while loop will stop. When both are true it means that I have a value to process. The second result may look odd to you. I didn't really need to use found? but I did to emphasize where the second result was going to come from. You can as easily delete "found?" from the line - the condition will still work. find/only series value finds the value in the series. If the value is found then the result of this is the same series but it's index (position) modified to where the value occurred. I capture this result into the same variable "series". If the value was not found you get a none! So the series index gets moved up if a value is found. It gets moved to the value. The body part of the while loop runs for each value that is found. It adds the value to the result and then it moves the series index again to prevent an infinite loop. I hope that is helpful! Regards, Brett.