Page:
Comparators
Pages
Advanced Compilation
Atom
Bootstrapped ClojureScript FAQ
Bootstrapping the Compiler
Building the compiler
ClojureScript Puppet Manifest
Common Problems
Companies Using ClojureScript
Comparators
Compile Time Type Checking
Compiler Options
Cursive
Custom Build Tools
Custom REPLs
Dependencies
Developers
Differences from Clojure
Emacs & Inferior Clojure Interaction Mode
Emacs & Inferior Clojure Interaction Mode
Enhanced JavaScript Module Support
Enhanced Node.js Modules Support
Exception Handling
FAQ (for JavaScript developers)
Google Closure Library
Google Closure
Google Summer of Code 2015
Home
JavaScript Library Preprocessing
JavaScript Module Support (Alpha)
Launch Plan
Light Table
Optional Self hosting
Packaging Foreign Dependencies
Patches
Providing IO utilities
Quick Start
REPL Options
REPL stack traces
Rationale
Reader
Release plans
Remote REPL
Reporting Bootstrap Issues
Reporting Issues
Road Map
Running REPLs
Running the tests
Singleton Pattern Externs Inference Support
Source maps
Sublime Text 2
Testing
The REPL and Evaluation Environments
Underpinnings
Using cljc
Vim
Windows Setup
Working with Javascript classes
_Sidebar.md
lein cljsbuild
No results
3
Comparators
Mike Fikes edited this page 2016-02-24 15:27:35 -05:00
Table of Contents
Note: There is now an
IComparableprotocol, whichcljs.core/comparewill make use of.
Problem statement
TODO
Terms
- comparison fn: boolean valued fn
- comparator: -/0/+ valued fn
- comp: either of the above
(These terms are not good, but I wanted one-word ways to talk about each idea below.)
Issues
- different underlying platform API
- Java expects comparators (instances of Comparator)
- goog expects comparison fns
- users care about composability, not abstractions
- Clojure fns can be either comparators or comparison fns
- implementation via wrapper in AFn's Comparable implementation
- newly created fns just work
- protocols not helpful for implementation
- if fns were some kind of IComparable, would just have to convert back to plain fns for goog to use them
- don't see any obvious performance win
- protocols not helpful for consumers
- making comp writers implement a protocol is just introducing a Javaism
Proposed Approach
- usage
- no Comparable protocol
- just use fns
- implementation
- do AFn's wrapping work in a helper fn that wraps user fns inside sort
I am pretty confident about the usage. Less confident about implementation, but this can be improved later.