sci 2023-11-09

If I evaluate something like (sort ["πŸ₯š" "πŸ”"]) in node SCI, what system is responsible for the sort? Is it happening in JS?

This is just using CLJS's sort function

cljs.core/sort
([coll] [comp coll])
  Returns a sorted sequence of the items in coll. Comp can be
   boolean-valued comparison function, or a -/0/+ valued comparator.
   Comp defaults to compare.

cljs.core/compare
([x y])
  Comparator. Returns a negative number, zero, or a positive number
  when x is logically 'less than', 'equal to', or 'greater than'
  y. Uses IComparable if available and google.array.defaultCompare for objects
 of the same type and special-cases nil to be less than any other object.

The behavior seems to be the same in JS for this example

cljs.user=> (sort ["πŸ₯š" "πŸ”"])
("πŸ”" "πŸ₯š")
cljs.user=> (.sort #js  ["πŸ₯š" "πŸ”"])
#js ["πŸ”" "πŸ₯š"]

Thanks! Yes, it’s the same in JS, which led me to start thinking about this. But if I understand correctly it is not JS per se that is responsible for the sorting? I guess the unicode characters carry a collating order with them or something.

true, CLJS has its own sorting system as described in the docstrings

it does not simply call .sort and calls it a day

πŸ™ 1