Mercerenies / gdlisp

Lisp on the Godot platform
GNU General Public License v3.0
140 stars 1 forks source link

Standardize Equality #61

Closed Mercerenies closed 2 years ago

Mercerenies commented 2 years ago

Currently, we have one equality operator: =. = simply compiles blindly to the Godot == equality operator, which works well enough on numbers and strings. It also seems to work on arrays but not dictionaries for some reason. Most importantly, it's not extensible for custom classes, so it doesn't work on user-defined classes, or cons cells, or even symbols.

We need proper equality operators in GDLisp. First, let's take a look at the way other languages do it.

On the one side, we have other recent multiple-dispatch languages like Julia. == is a multimethod in Julia (like every function), which has, at least on my version of the interpreter, 155 overloads. We could heavily overload our existing = once we have #11.

On the other extreme, Common Lisp has no fewer than five equality operators for different purposes.

Needless to say, there's likely a balance to be struck between the two extremes. I'd love to have a multimethod implementation efficient enough to support Julia's approach, but I'm not confident that that's the reality of the situation.

Mercerenies commented 2 years ago

Closed by 0f87968. There are now two equality functions in GDLisp.

a b = equal?
1 1 true true
1 1.0 true true
1 "1" error false
nil nil true true
[1] [1] true true
{'a 1} {'a 1} false true
'('a 1) '('a 1) false true
['(1)] ['(1)] false true
((literally PoolIntArray) [0]) [0] error true