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

World: r3wp

[Core] Discuss core issues

Andreas
10-Dec-2010
[722]
Yes.
BrianH
10-Dec-2010
[723x2]
If so, please mention that in a ticket comment.
It might be a compiler problem.
Andreas
10-Dec-2010
[725]
A library problem, yes.
BrianH
10-Dec-2010
[726]
Are you talking about R2 or R3?
Andreas
10-Dec-2010
[727x2]
Read what I said above: A110
Two tests in the example code given in the ticket seem wrong to me.
BrianH
10-Dec-2010
[729]
Right, sorry. I read that after I sent the message.
Andreas
10-Dec-2010
[730x3]
; Verification using SAME?
>> set [c d] sort reduce [a: "a" b: "a"]
== ["a" "a"]
>> same? c a
== false  ; should be true
>> same? c b
== true  ; should be false
>> same? d a
== true  ; should be true
>> same? d b
== false  ; should be false
The last two tests should be the other way round, no?
same? d a ; should be false
same? d b ; should be true
BrianH
10-Dec-2010
[733]
Fixed.
Andreas
10-Dec-2010
[734]
Thanks
Steeve
10-Dec-2010
[735]
Btw, by reading again your samples Brian, I think now it"s weird 
for a quick sort.
Not exactly what I expected....
Andreas
10-Dec-2010
[736]
At least on Linux, it definitely is a qsort.
BrianH
10-Dec-2010
[737]
It might be using the C library qsort.
Andreas
10-Dec-2010
[738]
Calling the C librabry's qsort(3).
BrianH
10-Dec-2010
[739]
Definitely mention that in a ticket comment. We might be able to 
make this a platform-specific ticket.
Andreas
10-Dec-2010
[740x2]
Not really, I fear.
qsort(3) is not guaranteed to be stable.
BrianH
10-Dec-2010
[742]
I mean, mention that it works on Linux, if that is what your tests 
reveal.
Andreas
10-Dec-2010
[743x2]
(Neither is it guaranteed to be a quicksort.)
That it works on Linux is pure coincidence.
BrianH
10-Dec-2010
[745]
I ran into the problem when I was sorting words in a block and the 
bindings mattered.
Andreas
10-Dec-2010
[746]
If we want SORT to be stable, the implementation will have to abandon 
the use of qsort(3).
BrianH
10-Dec-2010
[747]
That would explain why the ticket is still not fixed. Please mention 
this in a ticket comment - it might lead to changing its status.
Andreas
10-Dec-2010
[748x2]
You can of course hack stability into qsort() by falling back to 
comparing adresses if values are the same.
Not sure if Carl likes that :)
BrianH
10-Dec-2010
[750x2]
That won't work, because we are comparing EQUAL? (maybe plus /case), 
not SAME?.
Does qsort take a comparison function? If so, it might be a error 
in that function.
Andreas
10-Dec-2010
[752]
I'm talking about the C side of things here.
BrianH
10-Dec-2010
[753]
Same here - a C function pointer.
Andreas
10-Dec-2010
[754x4]
Then I don't understand your EQUAL?/SAME? remark.
If two elements are EQUAL?, fall back to comparing their addresses 
in memory.
Won't work for linked lists, will work for arrays stored consecutively.
Sorry, missed that. Yes, qsort takes a callback used for comparison. 
Here's the decl:


void qsort(void *base, size_t nitems, size_t size, int (*compar)(const 
void *, const void*));
BrianH
10-Dec-2010
[758]
Sorry, I just got that you were talking about using <= instead of 
<.
Andreas
10-Dec-2010
[759x2]
My remark above was to the effect: if two elements are EQUAL? compare 
their INDEX? instead. This may sound ridiculous in context of REBOL's 
SORT, but it is no problem in C.
As the comparison callback gets pointers to the elements anyway.
BrianH
10-Dec-2010
[761]
I still think that you need to write this stuff in a ticket comment. 
Writing it here will have no effect - the ticket is where the real 
discussion happens, and I don't seem to understand your argument 
well enough in this case to paraphrase you there.
Andreas
10-Dec-2010
[762]
I'm writing already.
BrianH
10-Dec-2010
[763]
All :) intended, of course.
Andreas
10-Dec-2010
[764]
In any case, I find this channel more fruitful for interactive discussion.
BrianH
10-Dec-2010
[765]
True. But Carl won't see it.
Sunanda
10-Dec-2010
[766]
BrianH <And not well enough documented either. I don't really know 
how /compare works, not completely.>

Comparators and the stable-sort trick (-1, 0 +1) are documented here 
in an old change log. It never made it into the dictionary for SORT:
    http://www.rebol.com/docs/changes-2-5.html#section-72
BrianH
10-Dec-2010
[767x2]
Documentation request referencing that link added here: http://curecode.org/rebol3/ticket.rsp?id=1793
Thanks :)
Ladislav
11-Dec-2010
[769]
Re -1 0 1 - as far as I remember, I read somewhere about negative, 
0, positive?
BrianH
11-Dec-2010
[770]
That works too:

>> sort/compare [20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 
1] func [x y] [case [x < y [3] x = y [0] 'else [-4]]]
== [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20]
Gabriele
11-Dec-2010
[771]
Are we talking R2's sort or R3's sort here? I know for a fact that 
R2's sort is stable. Obviously you can't get a stable sort if you 
use a comparator function and you return a logic! value.