Equality
The most common way to test equality is with =
For numeric equality (IEEE) use ==
For bytewise equality use identical?
The behavior and names are based on Clojure's implementation. Read their docs here: https://clojure.org/guides/equality
Also check out slosh/tests/equality.slosh
for some examples.
-
=
-
(= 2 0x2)
istrue
(comparing an int to a byte) -
(= 2 2.0)
isfalse
(comparing an int to a float) -
(= 0.0 -0.0)
istrue
-
(= NaN NaN)
isfalse
-
state.rs
defines special forms object with keyequal
mapped to the name=
. -
compile.rs
matches onenv.specials().equal
and generates opcodeEQUAL
-
exec_loop.rs
maps opcodeEQUAL
to functionis_equal
-
vm.rs
is_equal
converts each arg to aValue
(in case it needs to be dereferenced) and callsis_equal_pair
-
vm.rs
is_equal_pair
does a complex test for equality- check if both args are Byte or Int and if so, converts both to
i64
withValue::get_int
and compares with rust native==
- check if both args are numbers (Byte, Int, or Float) and if so, converts both to
f64
withValue::get_float
and compares with rust native==
- check if both args are Byte or Int and if so, converts both to
-
-
==
-
(== 1 1.0)
istrue
(comparing an int to a float) -
(== 0.0 -0.0)
istrue
-
(== NaN NaN)
isfalse
-
returns true whenever
=
does, but also returns true for numbers that are numerically equal -
when comparing two floats, converts two both to
f64
and compares with native f64==
-
does not use F56::PartialEq implementation
-
state.rs
defines special forms object with keynumeq
mapped to the name==
. -
compile.rs
callscompile_list
which callscompile_special
which callscompile_math
incompile_math.rs
-
compile_math.rs
compile_math
matches onenv.specials().numeq
and generates opcodeNUMEQ
-
exec_loop.rs
maps opcodeNUMEQ
to functioncompare_numeric
and passes a comparator|a,b| a == b
-
macros.rs
compare_numeric
- checks if either argument is a
Float
and if so, converts both tof64
withget_primitive_float
macro and uses the comparator - checks if either argument is a
Int
and if so, converts both toi64
withget_primitive_int
macro and uses the comparator
- checks if either argument is a
-
-
identical?
-
(identical? 1 1)
istrue
-
(identical? 1 1.0)
isfalse
(different types) -
(identical? 0.0 -0.0)
isfalse
(comparing floats with different bit patterns) -
(identical? NaN NaN)
might betrue
orfalse
. There are trillions of different bit patterns that represent NaN in IEEE 754 -
is the only equality comparison that uses
Value::PartialEq
implementation which is always false for different types of Values -
using identical equality for floats causes problems with hashing. #125 identical equality is 'too strict' in that you probably expect that +0 and -0 should hash to the same thing, but they don't rendering hash tables
-
state.rs
defines special forms object with keyeq
mapped to the nameidentical?
. -
compile.rs
matches onenv.specials().eq
and generates opcodeEQ
-
exec_loop.rs
maps opcodeEQ
to functionis_identical
-
vm.rs
is_identical
converts each arg to aValue
(in case it needs to be dereferenced) and comparesval1 == val2
which usesValue::PartialEq
implementation
-
-
assert-equal
- based on
=
- is a macro defined in core.slosh which checks if the arguments are
=
and throws an error if they are not
- based on
-
not=
- defined in
vm/core.slosh
as the negation of=
- defined in
-
not==
- defined in
vm/core.slosh
as the negation of==
- defined in