clarity-lang / reference

The Clarity Reference
146 stars 34 forks source link

Rename is-eq function #38

Open njordhov opened 3 years ago

njordhov commented 3 years ago

The is-eq function tests for equality, but the name is cryptic. It could benefit from being renamed to a more understandable term such as equal.

(equal 1 1)             ;; Returns true
(equal true false)      ;; Returns false
(equal "abc" 234 234)   ;; Throws type error

The naming of this Clarity function has evolved from eq via eq? to is-eq, with the affixes intended to indicate that the function returns a boolean. However, in Clarity, the other predicates starting with is- are all tests for type variants: is-ok, is-err, is-some, and is-none, making is-eq an odd duck. Also, while these predicates take a single argument, the equality function is variadic, making is- grammatically incorrect. Other predicates like not and > don't start with is- so it is not a consistent pattern. The equality function should not be prefixed with is-.

While eq is historically used in Lisp languages to compare for object identity, it is an abbreviation that may not be generally obvious. For Clarity, we should favor terms that preferably can be understood without having to consult the language reference. Using equal would be a good choice. For precedence, equal is also used in other Lisp dialects including Common Lisp as a more general equality test.

A compact alternative is to use = . As precedence, it is already used for equality in the Clojure lisp dialect. There is currently no function with this name in Clarity, despite the availability of < and >, so its inclusion would make Clarity more complete.

(= 1 1)             ;; Returns true
(= true false)      ;; Returns false
(= "abc" 234 234)   ;; Throws type error

Related: https://github.com/blockstack/stacks-blockchain/issues/1126 https://github.com/blockstack/stacks-blockchain/issues/998