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

Reverse select?

 [1/11] from: kpeters:otaksoft at: 7-Aug-2007 16:03


Given states: [ "AZ" "Arizona" "WY" "Wyoming" "FL" "Florida" ] How can I 'reverse select', i.e. find "WY" given "Wyoming" ? TIA, Kai

 [2/11] from: tim-johnsons:web at: 7-Aug-2007 15:18


On Tuesday 07 August 2007, Kai Peters wrote:
> Given > > states: [ "AZ" "Arizona" "WY" "Wyoming" "FL" "Florida" ] > > How can I 'reverse select', i.e. find "WY" given "Wyoming" ? > > TIA, > Kai
Hi Kai: I use this: before: func[ "Returns item *before* 'key in 'data, if found." data[series!] key[any-type!] /local found][ either found: find data key[pick data (index? found) - 1][none] ] NOTE: this code was slight altered from my own library, since I use 'def instead of 'fun (local variables generated automatically)

 [3/11] from: gregg:pointillistic at: 7-Aug-2007 17:20


Hi Kai, KP> states: [ "AZ" "Arizona" "WY" "Wyoming" "FL" "Florida" ] KP> How can I 'reverse select', i.e. find "WY" given "Wyoming" ?
>> states: [ "AZ" "Arizona" "WY" "Wyoming" "FL" "Florida" ]
== ["AZ" "Arizona" "WY" "Wyoming" "FL" "Florida"]
>> select states "WY"
== "Wyoming"
>> select reverse states "Wyoming"
== "WY" Obviously that only works in simple cases, where your values are unique, but it does work. :) -- Gregg

 [4/11] from: pwawood:gm:ail at: 8-Aug-2007 7:21


>> states: ["AZ" "Arizona" "WY" "Wyoming" "FL" "Florida"]
== ["AZ" "Arizona" "WY" "Wyoming" "FL" "Florida"]
>> first back find states "Wyoming"
== "WY" Peter On Wednesday, August 8, 2007, at 07:03 am, Kai Peters wrote:

 [5/11] from: kpeters:otaksoft at: 7-Aug-2007 16:34


Wow - thank you so much all of you - that was quick and lots to choose from! Kai

 [6/11] from: tim-johnsons:web at: 7-Aug-2007 16:12


On Tuesday 07 August 2007, Kai Peters wrote:
> Wow - thank you so much all of you - that was quick and > lots to choose from! > > Kai
first back find states "not there" ** Script Error: back expected series argument of type: series port ** Near: first back find states "not there"
>> before states "not here"
== none ;; :-) cheers tim

 [7/11] from: anton:wilddsl:au at: 9-Aug-2007 3:17


states: ["AZ" "Arizona" "WY" "Wyoming" "FL" "Florida"] all [pos: find states "Wyoming" pick pos -1] ;== "WY" Anton.

 [8/11] from: ale870::gmail::com at: 8-Aug-2007 21:35


Hello, regarding the solution proposed by Gregg, I have a question:
>> select reverse states "Wyoming"
I think in such case the solution could be very slow, since Rebol reverses the data every time. Is it right? If so, is there any way to avoid the reverse process, but communicating to Rebol to search in back? Thank you! On 8/8/07, Anton Rolls <anton-wilddsl.net.au> wrote:
> states: ["AZ" "Arizona" "WY" "Wyoming" "FL" "Florida"] > all [pos: find states "Wyoming" pick pos -1]
<<quoted lines omitted: 11>>
> To unsubscribe from the list, just send an email to > lists at rebol.com with unsubscribe as the subject.
-- --Alessandro

 [9/11] from: anton:wilddsl:au at: 9-Aug-2007 12:46


SELECT does not have any refinement to control search direction. You could do: select reverse copy states "Wyoming" But I don't recommend that because it's quite inefficient, which would affect large datasets. Regards, Anton.

 [10/11] from: tim-johnsons:web at: 9-Aug-2007 14:33


On Wednesday 08 August 2007, Anton Rolls wrote:
> SELECT does not have any refinement to control > search direction. > > You could do: > > select reverse copy states "Wyoming" > > But I don't recommend that because it's quite inefficient, > which would affect large datasets.
A function (such as my 'before function) that uses: either found: find data key[pick data (index? found) - 1][none] Is easy enough to write and is probably acceptably efficient, but to implement it in the "C" code so that 'select would have a 'before refinement would be most useful... and speed up performance. MTCW Tim

 [11/11] from: ale870:g:mail at: 10-Aug-2007 22:09


I agree with you. It could be a good refinement a /reverse option! On 8/10/07, Tim Johnson <tim-johnsons-web.com> wrote:
> On Wednesday 08 August 2007, Anton Rolls wrote: > > SELECT does not have any refinement to control
<<quoted lines omitted: 36>>
> To unsubscribe from the list, just send an email to > lists at rebol.com with unsubscribe as the subject.
-- --Alessandro

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted