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

none? ???

 [1/8] from: pyxos::netcourrier::com at: 18-Apr-2002 16:08


Hi, I got an input file like this : 100002 050042011006470 100002 050100000000000 100003 050042011006470 100004 050042011003653 100005 050042011004029 100006 050049750304500 100007 250042011006470 100007 250100000000000 100008 250042011003653 100009 250042011004029 100010 250049750304500 100011 060042011006470 and the following code : tcs: =5B =5B tcgrp01 =2205=22 =2206=22 =2207=22 =2215=22 =2216=22 =2217=22 =2225=22 =2226=22 =2227=22 =2235=22 =2236=22 =2237=22 =5D =5B tcgrp02 =2202=22 =5D =5D texte: read/lines output offset: 7 foreach ligne texte =5B foreach grp tcs =5B tc: remove/part copy/part ligne (offset + 2) offset ; Keep the two first characters after the index and the extra space if not none? =5B select grp tc =5D =5B print rejoin =5B tc =22-=22 first grp =5D =5D =5D =5D In order to test if tc is included in the block. If so, it should print the first element of the sub block. Currently, it always prints the first element. Why ? TIA ------------------------------------------------- =22Sound Mind, Sound Body=22 Juv=E9nal =22Lire et =EAtre curieux, c'est la m=EAme chose=22 Pascal Quignard =22Qui triomphe de lui-m=EAme poss=E8de la force=22 Lao-Tseu, extrait du Tao Te King =22Dans la course =E0 la qualit=E9, il n'y a pas de ligne d'arriv=E9e=22 David Kearns Allez voir mon site : http://www.desala.org ------------------------------------------------------------- NetCourrier, votre bureau virtuel sur Internet : Mail, Agenda, Clubs, Toolbar... Web/Wap : www.netcourrier.com T=E9l=E9phone/Fax : 08 92 69 00 21 (0,34 =80 TTC/min) Minitel: 3615 NETCOURRIER (0,15 =80 TTC/min)

 [2/8] from: greggirwin:mindspring at: 18-Apr-2002 10:43


Hi Richard, <<...In order to test if tc is included in the block. If so, it should print the first element of the sub block. Currently, it always prints the first element. Why ? >> I haven't had my coffee yet this morning so I'm not clear on exactly what isn't working for you. I ran things here (manually putting the data in texte) and I got the following results: 05-tcgrp01 05-tcgrp02 05-tcgrp01 05-tcgrp02 05-tcgrp01 05-tcgrp02 05-tcgrp01 05-tcgrp02 05-tcgrp01 05-tcgrp02 05-tcgrp01 05-tcgrp02 25-tcgrp01 25-tcgrp02 25-tcgrp01 25-tcgrp02 25-tcgrp01 25-tcgrp02 25-tcgrp01 25-tcgrp02 25-tcgrp01 25-tcgrp02 06-tcgrp01 06-tcgrp02 If that's not what you're after, could you break it down a little more for us (e.g. "The first pass should have tc="05" and the select on tcs/1 should return "06", which means it exists, so it should print 'tcgrp01)? Also, if you haven't already, sprinkle some print statements in there to watch the values on each pass. That might tell you a lot. --Gregg

 [3/8] from: pyxos:netcourrier at: 18-Apr-2002 22:56


I want the first element to be printed only if the value if tc is found in the block, therefore if tc = 05 it should print tcgrp01, if 06 prints tcgrp01, if 02 prints tcgrp02. If not found nothing should print. Is it clear enough ? ----Message d'origine----
>De: =22Gregg Irwin=22 <greggirwin=40mindspring.com> >A: <rebol-list=40rebol.com>
<<quoted lines omitted: 41>>
>rebol-request=40rebol.com with =22unsubscribe=22 in the >subject, without the quotes.
------------------------------------------------- =22Sound Mind, Sound Body=22 Juv=E9nal =22Lire et =EAtre curieux, c'est la m=EAme chose=22 Pascal Quignard =22Qui triomphe de lui-m=EAme poss=E8de la force=22 Lao-Tseu, extrait du Tao Te King =22Dans la course =E0 la qualit=E9, il n'y a pas de ligne d'arriv=E9e=22 David Kearns Allez voir mon site : http://www.desala.org ------------------------------------------------------------- NetCourrier, votre bureau virtuel sur Internet : Mail, Agenda, Clubs, Toolbar... Web/Wap : www.netcourrier.com T=E9l=E9phone/Fax : 08 92 69 00 21 (0,34 =80 TTC/min) Minitel: 3615 NETCOURRIER (0,15 =80 TTC/min)

 [4/8] from: carl:rebol at: 18-Apr-2002 15:06


Simply, change: if not none? [ select grp tc ] [ print rejoin [ tc "-" first grp ] ] To: if select grp tc [ print rejoin [ tc "-" first grp ] ] -Carl At 4/18/02 10:56 PM +0200, you wrote:

 [5/8] from: anton:lexicon at: 19-Apr-2002 15:39


Now you can see clearly what is wrong. Your code is asking if a block is none. A block is never none. You could make it better by removing the enclosing brackets: if not none? select grp tc [ ... As Carl has pointed out below, that simplifies further. You can think of the square brackets as "protecting" their contents. The value of a block is just a block... You must do something with the block before you will get a value out of it. Either reduce it or do it or pick a value out of it. You can put totally buggy code into a block, and it won't cause a error until you try to reduce that block or that bit of buggy code. eg. This is a valid block: [aaksjdfhkjdfhalkdhfweioraweriuwer] Now I read your original post I think you want this: if find grp tc [ print rejoin [ tc "-" first grp ] ] Anton.

 [6/8] from: joel:neely:fedex at: 19-Apr-2002 7:37


Hi, Richard, Richard Coffre wrote:
> Hi, > I got an input file like this :
<<quoted lines omitted: 27>>
> In order to test if tc is included in the block. If so, it should print the first element of the sub block. > Currently, it always prints the first element. Why ?
There are at least three major flaws in the above code: 1) You are handing NONE? a *block* when you write if not none? [ select grp tc ] I suspect you confused square brackets with parentheses, but no punctuation is needed at all. Since any block value (no matter what contents) differs from NONE? , the test NOT NONE? [...] always succeeds. 2) You have no exit from the inner loop after success, so the subsequent groups within TCS will be tested even if after finding the appropriate value (and -- based on the previous comment -- you'll get bogus output from subsequent tests). 3) You are using SELECT instead of FIND. That will give you an error if you are searching for e.g. "37" because SELECT returns the value *following* the search target (and there's nothing after "37", so you'll get NONE). There are also the minor inefficiencies that: 1) You are extracting the tested substring on every pass through the inner loop, even though it shouldn't change. 2) You are copying and then discarding the prefix instead of just copying the part you need. And a semantic confusion that OFFSET isn't actually the offset into the string of the part of interest, it is the amount to discard. If you're discarding 7 characters, then the portion of interest begins at position 8 (thanks to the 1-origin mess). Fixing those problems, and simulating your input by parsing the sample string... text: parse/all {100002 050042011006470 100002 050100000000000 100003 050042011006470 100004 050042011003653 100005 050042011004029 100006 050049750304500 100007 250042011006470 100007 250100000000000 100008 250042011003653 100009 250042011004029 100010 250049750304500 100011 060042011006470} "^/" tcs: [ [ tcgrp01 "05" "06" "07" "15" "16" "17" "25" "26" "27" "35" "36" "37" ][ tcgrp02 "02" ] ] inset: 8 foreach line text [ use [tc] [ tc: copy/part at line inset 2 foreach grp tcs [ if found? find grp tc [ print rejoin [ tc "-" first grp ] break ] ] ] ] We get this output: 05-tcgrp01 05-tcgrp01 05-tcgrp01 05-tcgrp01 05-tcgrp01 05-tcgrp01 25-tcgrp01 25-tcgrp01 25-tcgrp01 25-tcgrp01 25-tcgrp01 06-tcgrp01 Note that the sample data you supplied all fall within the first group, however... text: parse/all {100002 050042011006470 100002 010100000000000 100003 020042011006470 100004 030042011003653 100005 040042011004029 100006 050049750304500 100007 060042011006470 100007 070100000000000 100008 080042011003653 100009 090042011004029 100010 100049750304500 100011 110042011006470} "^/" is a test data set that exercises both data groups and also your do nothing if not found case: 05-tcgrp01 02-tcgrp02 05-tcgrp01 06-tcgrp01 07-tcgrp01 Hope this helps! -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 ]

 [7/8] from: joel:neely:fedex at: 19-Apr-2002 8:10


Hi, again, Richard, I forgot one other performance issue I intended to raise: Richard Coffre wrote:
> tcs: [ > [ tcgrp01
<<quoted lines omitted: 12>>
> ] > ]
There's a lot of overhead involved in your two-level looping (both in time and in code complexity) that can be eliminated with a little pre-processing of your search data structure. It's easy to write a helper function that transforms your TCS into a simple block of key+value pairs... tcs: [ [ tcgrp01 "05" "06" "07" "15" "16" "17" "25" "26" "27" "35" "36" "37" ] [ tcgrp02 "02" ] ] unfold: func [groups /local result val] [ result: copy [] foreach group groups [ val: first group foreach key next group [ either found? find result key [ print rejoin ["Error: '" key "' already used!"] ][ insert insert tail result key val ] ] ] result ] The error detection is for free... ;-) The UNFOLD function walks across the entire group structure, but only once. The overhead of doing so is amortized across all of the input records, that now can use the native SELECT (which will be much faster than repeating the traversal in interpreted code for every input line). Now the work of processing your input data is much simpler: text: parse/all {100002 050042011006470 100002 050100000000000 100003 150042011006470 100004 250042011003653 100005 350042011004029 100006 450049750304500 100007 550042011006470 100007 020100000000000 100008 650042011003653 100009 750042011004029 100010 850049750304500 100011 060042011006470} "^/" tcs-pairs: unfold tcs inset: 8 foreach line text [ use [tc val] [ tc: copy/part at line inset 2 if found? val: select tcs-pairs tc [ print rejoin [ tc "-" val ] ] ] ] We get the following results: 05-tcgrp01 05-tcgrp01 15-tcgrp01 25-tcgrp01 35-tcgrp01 02-tcgrp02 06-tcgrp01 (Note that I changed some of the data to verify that both groups were present, and that the "do nothing if not found" rule would be followed.) -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 ]

 [8/8] from: richard:coffre:francetelecom at: 19-Apr-2002 15:23


Hi Joel, Thanks for this optimization I'll test later because so far it works and I don't manage the optimization. Richard -----Message d'origine----- De : Joel Neely [mailto:[joel--neely--fedex--com]] Envoy=E9 : vendredi 19 avril 2002 15:11 =C0 : [rebol-list--rebol--com] Objet : [REBOL] Re: none? ??? Hi, again, Richard, I forgot one other performance issue I intended to raise: Richard Coffre wrote:
> tcs: [ > [ tcgrp01
<<quoted lines omitted: 12>>
> ] > ]
There's a lot of overhead involved in your two-level looping (both in time and in code complexity) that can be eliminated with a little pre-processing of your search data structure. It's easy to write a helper function that transforms your TCS into a simple block of key+value pairs... tcs: [ [ tcgrp01 "05" "06" "07" "15" "16" "17" "25" "26" "27" "35" "36" "37" ] [ tcgrp02 "02" ] ] unfold: func [groups /local result val] [ result: copy [] foreach group groups [ val: first group foreach key next group [ either found? find result key [ print rejoin ["Error: '" key "' already used!"] ][ insert insert tail result key val ] ] ] result ] The error detection is for free... ;-) The UNFOLD function walks across the entire group structure, but only once. The overhead of doing so is amortized across all of the input records, that now can use the native SELECT (which will be much faster than repeating the traversal in interpreted code for every input line). Now the work of processing your input data is much simpler: text: parse/all {100002 050042011006470 100002 050100000000000 100003 150042011006470 100004 250042011003653 100005 350042011004029 100006 450049750304500 100007 550042011006470 100007 020100000000000 100008 650042011003653 100009 750042011004029 100010 850049750304500 100011 060042011006470} "^/" tcs-pairs: unfold tcs inset: 8 foreach line text [ use [tc val] [ tc: copy/part at line inset 2 if found? val: select tcs-pairs tc [ print rejoin [ tc "-" val ] ] ] ] We get the following results: 05-tcgrp01 05-tcgrp01 15-tcgrp01 25-tcgrp01 35-tcgrp01 02-tcgrp02 06-tcgrp01 (Note that I changed some of the data to verify that both groups were present, and that the "do nothing if not found" rule would be followed.) -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 ]

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