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

sorting a serie ....

 [1/18] from: garcia::a2::wanadoo::fr at: 18-Jun-2003 19:32


Hello, I try to find the minimun of a serie (print first reduce sort serie). the problem: the sort function works with the name of the variable instead of using their values, even if a use ":" example: a: 255 b: 1 c: -1
>> print sort[:a :b :c]
255 1 -1
>> print sort[a b c]
255 1 -1 And I would like: -1 1 255 how can I do this ? thanks arnaud

 [2/18] from: maximo:meteorstudios at: 18-Jun-2003 14:09


use compose as in: print sort compose [(a) (b) (c)] this will replace each value expression (anything within brackets) -max ----------- meteor Studios, T.D. ----------- Strong enough for a man, but made for a woman

 [3/18] from: maximo:meteorstudios at: 18-Jun-2003 14:15


try this too: print sort reduce [a b c] this might be better, it depends on what you are doing... used this way, you cannot leave words untouched, so it can't be used to build-up VID blocks... using compose like in my last mail, lets you convert only SOME values and leaves the others intact.. so:
>> probe sort compose [(a) (b) c]
[c 1 255] == [c 1 255] wheras:
>> probe sort reduce [(a) (b) c]
[-1 1 255] == [-1 1 255]
>>
HTH! -max ----------- meteor Studios, T.D. ----------- Strong enough for a man, but made for a woman

 [4/18] from: hallvard:ystad:helpinhand at: 18-Jun-2003 20:28


Hi, Arnaud, To sort your series, try this: print sort reduce [:a :b :c] ~H Dixit Arnaud (19.32 18.06.2003):

 [5/18] from: tim:johnsons-web at: 18-Jun-2003 10:23


* Arnaud <[garcia--a2--wanadoo--fr]> [030618 10:02]:
> Hello, > I try to find the minimun of a serie (print first reduce sort serie).
<<quoted lines omitted: 10>>
> And I would like: > -1 1 255
Hi Arnaud: Try this:
>print sort/reverse [a b c]
-1 1 255
>> a: 97
== 97
>> print sort/reverse [a b c]
-1 1 97 Kind of a tricky, huh? tim -- Tim Johnson <[tim--johnsons-web--com]> http://www.alaska-internet-solutions.com http://www.johnsons-web.com

 [6/18] from: joel:neely:fedex at: 18-Jun-2003 13:44


Hi, Arnaud, Arnaud wrote:
> Hello, > I try to find the minimun of a serie (print first reduce sort serie). >
Using your example, where the series is constructed from the values associated with a specific group of words:
>> a: 255
== 255
>> b: 1
== 1
>> c: -1
== -1 the minimum value is obtained by
>> first minimum-of reduce [a b c]
== -1 (since MINIMUM-OF returns a series reference). HTH! -jn- -- ---------------------------------------------------------------------- Joel Neely joelDOTneelyATfedexDOTcom 901-263-4446 Counting lines of code is to software development as counting bricks is to urban development.

 [7/18] from: greggirwin:mindspring at: 18-Jun-2003 13:15


Hi Arnaud, A> I try to find the minimun of a serie (print first reduce sort serie). You're not evaluating the block, so it's just treating it as a block of word! or get-word! values; just REDUCE it. You can also use MINIMUM-OF instead of sorting the block. first minimum-of reduce [a b c]
>> sort reduce [a b c]
== [-1 1 255] In your example, PRINT evaluates it for you which is why you end up seeing the values you want in the end. -- Gregg

 [8/18] from: brett:codeconscious at: 19-Jun-2003 8:39


Hi Arnaud, There has been plenty responses answering your problem, I just want to add a little more detail on the reason the solutions work. 1) A block is an ordered sequence of values. 2) [a b c] is a block of three values. These value are of type word! *not integer!* 3) Words can indirectly express other values. The user guide says "An indirectly expressed value is unknown until it is evaluated." In overview, in your example you need to sort [255 1 -1] which is a result of the evaluation of: REDUCE [a b c]. Sort [red green blue] sorts the three block values - words - using their spelling as you have discovered. Looking at some of the solutions. Max suggested: print sort compose [(a) (b) (c)] He was creating the [255 1 -1] block first using Compose. Max and others suggested print sort reduce [a b c] As noted above Reduce creates the [255 1 -1] that is subsequently sorted. Tim suggested: print sort/reverse [a b c] This works because Print implicitly carries out a REDUCE. Hope that was useful! Brett.

 [9/18] from: tim:johnsons-web at: 18-Jun-2003 15:52


I'm a short man among the tall when it comes to the talent on this list. I split my coding time between python and rebol, and find myself switching languages sometimes every hour. Besides the obvious trip-ups, like confusing ':' and '=' and '=' and '==', I still stumble over the issue of a rebol 'word', because there is no real comparison in other languages.... the subtleties remain elusive for me still ..... tim * Brett Handley <[brett--codeconscious--com]> [030618 15:06]:
> Hi Arnaud, > There has been plenty responses answering your problem, I just want to add a
<<quoted lines omitted: 60>>
> [rebol-request--rebol--com] with "unsubscribe" in the > subject, without the quotes.
-- Tim Johnson <[tim--johnsons-web--com]> http://www.alaska-internet-solutions.com http://www.johnsons-web.com

 [10/18] from: Al:Bri:xtra at: 19-Jun-2003 19:37


Tim (the short) wrote:
> I still stumble over the issue of a rebol 'word', because there is no real
comparison in other languages.... the subtleties remain elusive for me still ..... Here's my finger, it points at the moon. Don't confuse my finger (the word) for the moon (the value). :) My house is at {123 Fake Street, Fake Town, Fake Country}. My house is a value, {123 Fake Street, Fake Town, Fake Country} is a word referring to "My house". :) I write in words. Don't confuse my words (word) with my meaning (value). :) I hope that helps! What do I mean? :) Andrew J Martin ICQ: 26227169 http://www.rebol.it/Valley/ http://Valley.150m.com/

 [11/18] from: antonr:iinet:au at: 19-Jun-2003 18:08


Max, yes you can, look: str: "hello" view layout reduce ['button str 'field str] Maybe you didn't mean this, though.. Anton.

 [12/18] from: maximo:meteorstudios at: 19-Jun-2003 11:03


may I add that this is why I ALWAYS USE the PROBE statement, when veryfying functions. You get a clear picture... not an interpreted one. especially when examining blocks! -max ----------- meteor Studios, T.D. ----------- Strong enough for a man, but made for a woman

 [13/18] from: maximo::meteorstudios::com at: 19-Jun-2003 11:25

Recall: Re: sorting a serie ....


Maxim Olivier-Adlhoch would like to recall the message, "[REBOL] Re: sorting a serie ....".

 [14/18] from: maximo:meteorstudios at: 19-Jun-2003 11:24

Re: sorting a serie ....


ah, but here you can stumble upon a very bad proble... one that took me a few days to understand. using compose will bind the word at that time. if you just this: lbls: ["a" "b" "c"] gblval: "YIPpE!" vidblk: copy [] foreach lbl lbls [ append vidblk 'button append vidblk lbl append/only vidblk [ print [lbl gblval] ] ] gblval: "DAMN IT!" view layout vidblk pressing on any button, will actually always print "c YIPpE!" lbls: ["a" "b" "c"] gblval: "YIPpE!"now try this: vidblk: copy [] foreach lbl lbls reduce [ append vidblk 'button append vidblk lbl append/only vidblk reduce [ print [lbl gblval] ] ] gblval: "DAMN IT" view layout vidblk -max ----------- meteor Studios, T.D. ----------- Strong enough for a man, but made for a woman

 [15/18] from: maximo:meteorstudios at: 19-Jun-2003 12:07


ah, but here you can stumble upon a very bad proble... one that took me a few days to understand. using compose will bind the word at that time. if you just try this: lbls: ["a" "b" "c"] gblval: "YIPpE!" vidblk: copy [] foreach lbl lbls [ append vidblk 'button append vidblk lbl append/only vidblk [ print [lbl gblval] probe [lbl gblval] ] ] gblval: "DAMN IT!" probe vidblk view layout vidblk pressing on any button, will actually always print "c DAMN IT!" lbls: ["a" "b" "c"] gblval: "YIPpE!"now try this: vidblk: copy [] foreach lbl lbls [ append vidblk 'button append vidblk lbl append/only vidblk reduce [ 'print [lbl gblval] 'probe [lbl gblval] ] ] gblval: "DAMN IT" probe vidblk view layout vidblk pressing on any button, will actually always print "c DAMN IT!" ---------------------- NOW THE RIGHT ONE!!! ---------------------- lbls: ["a" "b" "c"] gblval: "YIPpE!"now try this: vidblk: copy [] foreach lbl lbls [ append vidblk 'button append vidblk lbl append/only vidblk compose/deep [ print "---global ref--" print [(lbl) gblval] probe [(lbl) gblval]=09 print "---local ref--" =09 print [(lbl) (gblval)] probe [(lbl) (gblval)] print "" ] ] gblval: "DAMN IT" probe vidblk view layout vidblk notice that in this example, gblval still stays a word with no value, because it was never evaluated before the print ( -max ----------- meteor Studios, T.D. ----------- Strong enough for a man, but made for a woman

 [16/18] from: maximo::meteorstudios::com at: 19-Jun-2003 12:36

composing blocks... (was Re: sorting a serie ....)


in my last mail I again pressed the send button whithout involuntarily.... all that was left to say is that in some circomstances, using compose is more specific. in my experience using vid dynamically, you often need to bind values to words at a precise point in time, other wise you risk running into very confusing code. since compose only reduces the selected expressions, you can more easily leave blocks intact for other funtions which expect words... like dialects, and specifically vid. also, compose has a /deep refinement which easily traverses nested blocks and will only reduce one teeny value deep in the third nest... I don't want anyone to feel like I'm trying to prove everyone wrong. Everyone posted usefull suggestions, and they all depend on context. Its just that I think compose is an underused word and since I've discovered it, MANY of my algorythms have become simpler. my two cents. -max ----------- meteor Studios, T.D. ----------- Strong enough for a man, but made for a woman

 [17/18] from: maximo:meteorstudios at: 19-Jun-2003 11:48

Re: sorting a serie ....


ignore this mail... it wasn't finished.. I am completing it as I have time... -max ----------- meteor Studios, T.D. ----------- Strong enough for a man, but made for a woman

 [18/18] from: lmecir:mbox:vol:cz at: 20-Jun-2003 22:43

Re: composing blocks... (was Re: sorting a serie ....)


Hi Max, ...snip... Its just that I think compose is an underused word and since I've discovered it, MANY of my algorythms have become simpler. ...snip... -max a little ad: have a look at: http://www.compkarori.com/vanilla/display/build+dialect Strong enough for a man, but made for me :-) -L

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