Why doesn't AppleScript list sortings work any more?

Hi,

on my Leopard system all sorting mechanism stopped working. Can someone help?
E.g. Hoare’s QuickSort …

on Qsort(array, leftEnd, rightEnd) -- Hoare's QuickSort Algorithm
	script a
		property l : array
	end script
	set {i, j} to {leftEnd, rightEnd}
	set v to item ((leftEnd + rightEnd) div 2) of a's l -- pivot in the middle
	repeat while (j > i)
		repeat while (item i of a's l < v)
			set i to i + 1
		end repeat
		repeat while (item j of a's l > v)
			set j to j - 1
		end repeat
		if (not i > j) then
			tell a's l to set {item i, item j} to {item j, item i} -- swap
			set {i, j} to {i + 1, j - 1}
		end if
	end repeat
	if (leftEnd < j) then Qsort(a's l, leftEnd, j)
	if (rightEnd > i) then Qsort(a's l, i, rightEnd)
end Qsort

Thanks
Tobias

Model: MacMini 2.26 GHz Intel Core 2 Duo
AppleScript: 2.0.1
Browser: Safari 531.21.10
Operating System: Mac OS X (10.5)

Can you be a little more explicit about “stopped working”?

I think you left out a line like a’s l from the end of the handler. Without it, there is no result.

. or perhaps forgot that the handler wasn’t actually meant to return a result, but to sort the list passed to it.

set myList to {5, 2, 4, 3, 1}
Qsort(myList, 1, (count myList))

return myList --> {1, 2, 3, 4, 5}

Edit: Corrected a wince-inducing spelling mistake.

Hi, I got the algorithm from here:
http://macscripter.net/viewtopic.php?pid=59460#p59460
And it worked fine until I changed the system to 10.5.x.

To be more explicit about it (Widows is the list I’d like to sort):

set WidowsCount to (count Widows)
log Widows
my Qsort(Widows, 1, WidowsCount)
log Widows

gives the following log result:

(*63, 83, 89, 91, 111, 145, 144*)
(*111, 144, 145, 63, 83, 89, 91*)

Cheers
Tobias

Hi, Tobias.

Your list has been sorted lexically, so presumably the list items are texts, not integers. If you want them sorted numerically, either coerce them to integers first or use ‘considering numeric strings’:

log Widows
considering numeric strings
	Qsort(Widows, 1, (count Widows))
end considering
log Widows

Thanks a lot, Nigel! This solved the problem!

Tobias