Skip to content

Conversation

@jfhamlin
Copy link
Contributor

@jfhamlin jfhamlin commented Aug 2, 2025

  • Add SortSlice function in pkg/lang/sort.go that performs stable in-place sorting
  • Add Compare function to support Clojure's compare semantics (nil handling, number, Comparable)
  • Update ToSlice to handle required types
  • Add transformation in rewrite.clj to replace java.util.Arrays.sort with SortSlice
  • Add transformation for clojure.lang.Util.compare to use Compare function
  • Implement Comparer interface for several Glojure core types, corresponding to Java Comparable

The implementation matches Clojure JVM semantics:

  • Stable sort (equal elements maintain order)
  • Comparator contract (-1/0/1 return values)
  • Proper nil handling (nil sorts before non-nil)
  • Support for custom comparators

Also sneaking in a format make command and some formatting fixes.

Fixes #66

H/t to @ingydotnet for the nudge and some of the tests :)

- Add SortSlice function in pkg/lang/sort.go that performs stable in-place sorting
- Add Compare function to support Clojure's compare semantics (nil handling, cross-type numeric comparison)
- Update ToSlice to handle all required types: nil→empty, IPersistentVector, IPersistentMap, string→char array
- Add transformation in rewrite.clj to replace java.util.Arrays.sort with SortSlice
- Add transformation for clojure.lang.Util.compare to use Compare function

The implementation matches Clojure JVM semantics:
- Stable sort (equal elements maintain order)
- Comparator contract (-1/0/1 return values)
- Proper nil handling (nil sorts before non-nil)
- Support for custom comparators
Signed-off-by: James Hamlin <jfhamlin@gmail.com>
Signed-off-by: James Hamlin <jfhamlin@gmail.com>
Signed-off-by: James Hamlin <jfhamlin@gmail.com>
Signed-off-by: James Hamlin <jfhamlin@gmail.com>
Signed-off-by: James Hamlin <jfhamlin@gmail.com>
Signed-off-by: James Hamlin <jfhamlin@gmail.com>
@jfhamlin jfhamlin merged commit 4e3baf3 into main Aug 2, 2025
2 checks passed
@jfhamlin jfhamlin deleted the sort branch August 2, 2025 06:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sort fails for lists and vectors

2 participants