r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Core] Discuss core issues

Sunanda
9-May-2010
[16510]
Yes you can:
sort/skip/compare s 4 [1 2 4 3]
== [1 2 8 a 1 2 6 b 1 2 7 c]
BrianH
9-May-2010
[16511]
Graham, no, noone can update that doc page, it's a permissions issue. 
All docs updates by anyone other than Carl are on hold.
Graham
9-May-2010
[16512x2]
someone = Carl
:)
BrianH
9-May-2010
[16514x2]
Ask in chat or CureCode, Carl won't see the request here.
It's best to ask in CureCode anyways, because the request will stay 
there where we can find it until the issue is fixed.
Graham
9-May-2010
[16516]
some of the browsers allow you to annotate the page so I can see 
my own notes
BrianH
9-May-2010
[16517]
But the people who would fix the docs won't see your notes.
Graham
9-May-2010
[16518x2]
But at least I will ...
And when we get the permissions to do so, we can then
BrianH
9-May-2010
[16520]
OK, good, that way you will remember to submit a CureCode ticket 
later.
Henrik
9-May-2010
[16521x2]
>> a: 0.24.26
== 0.24.26
>> poke a 2 155
== 0.155.26
>> a
== 0.24.26 ; huh?
fixed in R3 though.
Ladislav
9-May-2010
[16523x7]
>> a: b: 0.24.26
== 0.24.26

>> poke a 2 155

** Script error: poke does not allow tuple! for its value argument
if you consider that fixed, then I do agree with you
nevertheless, the behaviour in R2 looks reasonable too
(taking into account, that tuples are immutable)
re "ask in chat or CC" - I asked in chat, privately, but do not see 
any reaction yet, and I added a comment to CC #1571
also: http://eupat.ffii.org/
sorry, misplaced post
Henrik
9-May-2010
[16530]
since tuple are not series in R3, then I'd say it's fixed.
Maxim
10-May-2010
[16531]
tuple aren't immutable in R2 OR R3

>> a: 1.2.34
== 1.2.34
>> a/2: 33
== 33
>> a
== 1.33.34

this works in both R2 and R3
Steeve
10-May-2010
[16532]
nope, they are

>> a: b: 1.2.3
== 1.2.3
>> a/1: 33
== 33
>> a
== 33.2.3
>> b
== 1.2.3
Maxim
10-May-2010
[16533x2]
ok... yeah in that sense.
they aren't series.
Ladislav
10-May-2010
[16535]
tuple aren't immutable in R2 OR R3

 - it is discussed in http://www.rebol.net/wiki/Identity#Expressions_modifying_their_values

Tuples are exactly as mutable as integers in R2 as well as in R3
amacleod
11-May-2010
[16536x2]
BrainH asked: Didn't know you could put the /compare index in a block. 
Can you specify more than one index?

Sunanda says: Yes you can:
sort/skip/compare s 4 [1 2 4 3]
== [1 2 8 a 1 2 6 b 1 2 7 c]


That's great but can you do that with a block of blocks of  data....

example: 
s: [
	[1 2 8 a]
	[1 2 6 b] 
	[1 2 7 c]]
]
remove extra ]
Maxim
11-May-2010
[16538]
use a compare function for that
amacleod
11-May-2010
[16539]
So nothing as easy as Sunanda's example built into rebol?
Sunanda
11-May-2010
[16540x2]
To turn Maxim's comment into an example:

   sort/compare s func [a b] [
== [
    [1 2 6 b]
    [1 2 7 c]
    [1 2 8 a]
]
s
Oops that SORT line should be
   sort/compare s func [a b] [return a/3 < b/3]
Maxim
11-May-2010
[16542]
thanks... I was a bit lazy there  ;-)
amacleod
11-May-2010
[16543]
so something like this will give me a sort on multi indexes?
sort/compare s func [a b] [return a/4 < b/4 return a2 < b/2]
Maxim
11-May-2010
[16544x4]
btw return is never required at the end of a func .. and slows down 
rebol A LOT in tight loops.
amacleod... your example would stop at first compare (you're returning 
right away)
try this instead:

sort/compare s func [a b] [
	either  a/4 = b/4  [
		a2 < b/2
	][
		a/4 < b/4
	]
]
but not exactly sure of results...
Sunanda
11-May-2010
[16548]
For safe stable, sorting return -1, 0, +1 rather than true or false:
   http://www.rebol.com/docs/changes-2-5.html#section-72
amacleod
11-May-2010
[16549x2]
I do not know if that is what I want...i'm looking to prioritize 
each compare giving each a "weight"
example" 


sorting a list of first and last names first on last then on first 
in case of same last names
Sunanda
11-May-2010
[16551]
The basic compare function then (assuming you are sorting a block 
of objects) is:

   func [a b] [if a/surname = b/surname [return a/firstname < b/firstname] 
   return a/surname < b/surname]]
amacleod
11-May-2010
[16552]
so if I'm comparing 5 or 6 fields I would nest to if statements 5 
deep?
Sunanda
11-May-2010
[16553]
Basically, yes.....You may find a neat way of refactoring....Or JOINing 
keyfields so you can do a single compare....but that is the basic 
principle.
amacleod
11-May-2010
[16554]
thanks all
Maxim
11-May-2010
[16555]
late but here is an equivalent working example:

names: [
	["zz" "bb"] ["cc" "zz"] ["aa" "aa"]["bb" "ee"]
	["zz" "tt"] ["cc" "aa"] ["aa" "yy"]["bb" "aa"]
]
sort/compare names func [a b][
	either a/1 = b/1 [a/2 < b/2][a/1 < b/1]
]
probe names

== [ ["aa" "aa"] ["aa" "yy"] ["bb" "aa"] ["bb" "ee"] ["cc" "aa"] 
["cc" "zz"]  ["zz" "bb"] ["zz" "tt"] ]
amacleod
11-May-2010
[16556]
that limits it to comparisons on two fields...right?
Maxim
11-May-2010
[16557x2]
yep... as sunanda said, you need to chain the compares.


there might be a way of using ANY/ALL functions too, but it can be 
tricky ... though usually yields less code.
yields = requires
Sunanda
11-May-2010
[16559]
Something like this will sort on all fields
 

sort/compare s func [a b] [for n 1 length? a 1 [if a/:n < b/:n [return 
-1] if a/:n > b/:n [return +1]] return 0]