Fork me on GitHub
#sci
<
2023-11-09
>
pez16:11:26

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

borkdude16:11:55

This is just using CLJS's sort function

borkdude16:11:18

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.

borkdude16:11:44

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.

borkdude16:11:56

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

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

pez17:11:42

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.

borkdude17:11:38

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

borkdude17:11:48

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

πŸ™ 1