txlyre 1 day ago
parent
commit
1e11568b01
2 changed files with 285 additions and 290 deletions
  1. 281 287
      qistd.c
  2. 4 3
      std.qi

File diff suppressed because it is too large
+ 281 - 287
qistd.c


+ 4 - 3
std.qi

@@ -108,7 +108,8 @@ func list_pop_at(l, i) {
   return x
 }
 set_pseudomethod("list.popAt", list_pop_at)
-func list_sort(l, cmp=func (x, y): x > y) {
+func __cmp(x, y): x > y? 1: x < y? -1: 0
+func list_sort(l, cmp=__cmp) {
   if type(l) != "list"
     throw "expected first argument to be: list, but got: " + type(l)
   if type(cmp) != "function"
@@ -118,14 +119,14 @@ func list_sort(l, cmp=func (x, y): x > y) {
   var z = len(l)
   for var i = 0; i < z - 1; i++
     for var j = 0; j < z - 1 - i; j++
-      if cmp(l[j], l[j+1]) {
+      if cmp(l[j], l[j+1]) > 0 {
         let tmp = l[j]
         l[j] = l[j+1]
         l[j+1] = tmp
       }
   return l
 }
-func list_sorted(l, cmp=func (x, y): x > y) {
+func list_sorted(l, cmp=__cmp) {
   l = list_copy(l)
   return list_sort(l, cmp)
 }

Some files were not shown because too many files changed in this diff