Sort using a custom comparator: Difference between revisions

Line 932:
:<!wrt> List string =
list_vt2t (list_mergesort_cloref<string> (lst, cmp))
 
var one = 1
val p_one = addr@ one
 
fn
Line 1,022 ⟶ 1,019:
:<cloref> int =
let
(* Merely to demonstrate this is a closure instead of a
regular function, get the value of "one" from a global
variable. *)
val @(pf, fpf | p) = $UN.ptr_vtake{int} p_one
val one = !p
prval () = fpf pf
 
val m = length x
and n = length y
in
if m < n then
one1
else if n < m then
~one1
else
strcasecmp (x, y)
Line 1,046 ⟶ 1,036:
sort_by_calling_back_to_a_closure (lst : List string)
:<!wrt> List string =
(* Incorporate a closure into the sort implementation. (Standard C
does not have closures.) *)
let
fn
Line 1,054 ⟶ 1,042:
:<cloref> int =
let
(* Merely to demonstrate this is a closure instead of a
regular function, get the value of "one" from a global
variable. *)
val @(pf, fpf | p) = $UN.ptr_vtake{int} p_one
val one = !p
prval () = fpf pf
 
val m = length x
and n = length y
in
if m < n then
one1
else if n < m then
~one1
else
strcasecmp (x, y)
1,448

edits