ocaml: phase 6 List.sort + compare (+7 tests, 339 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 25s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 25s
compare is a host builtin returning -1/0/1 (Stdlib.compare semantics) deferred to host SX </>. List.sort is insertion-sort in OCaml: O(n²) but works correctly. List.stable_sort = sort. Tested: ascending int sort, descending via custom comparator (b - a), empty list, string sort.
This commit is contained in:
@@ -67,6 +67,14 @@
|
||||
(list "print_string" (fn (s) (begin (print s) nil)))
|
||||
(list "print_endline" (fn (s) (begin (println s) nil)))
|
||||
(list "print_int" (fn (i) (begin (print (str i)) nil)))
|
||||
;; Polymorphic compare — returns negative / 0 / positive like
|
||||
;; OCaml's Stdlib.compare. Defers to host SX `<` and `>`.
|
||||
(list "compare"
|
||||
(fn (a) (fn (b)
|
||||
(cond
|
||||
((< a b) -1)
|
||||
((> a b) 1)
|
||||
(else 0)))))
|
||||
;; Hashtbl primitives (one-element list cell holding a dict).
|
||||
;; Keys are coerced to strings via `str` so any value type works
|
||||
;; as a key (matches Hashtbl's polymorphic-key semantics).
|
||||
|
||||
Reference in New Issue
Block a user