A Quick Sort

#!/usr/bin/env mwnci
function QuickSort(arr) {
    tmp={}
    n=0
    while (n < len(arr)) {
        tmp = set(tmp, type(arr[n]), true)
	n++
    }
    if (len(keys(tmp)) > 1) {
        println("`sort`: Can't sort with mixed-type values")
	println(string(arr))
	exit(1)
    }
    tmp={}
    newArray = arr
    return qsort(newArray, 0, len(arr)-1);
}

function qsort(arr, start, end) {
    if ((end - start) < 1) {
        return arr;
    }

    pivot=arr[end]
    splitIndex=start
    i=start
    while (i < end) {
        if (arr[i] < pivot) {
	    arr=swap(arr, splitIndex, i)
	    splitIndex++
	}
	i++
    }
    arr=set(arr, end, arr[splitIndex])
    arr=set(arr, splitIndex, pivot)
    arr=qsort(arr, start, splitIndex-1)
    arr=qsort(arr, splitIndex+1, end)
    return arr;
 }

a=[]
foreach n in 1..100 {
a=push(a, random(10))
}

a=QuickSort(a)
println(a)