The difference between equators and = in the scheme?

> (eq? 1 1) #t > (eq? 1.1 1.1) #f > (= 1.1 1.1) #t 

This is the interaction window in DrScheme. Can someone explain the difference between = and eq? in the circuit?

+6
scheme racket
source share
4 answers

= compares numbers. uh if the parameters represent the same data object in memory. Eqv? should work in the second case, since it tests the same as eq? but specifically tests primitives. Read more about equalizer predicates in the circuit here .

+9
source share

I would suggest that since

uh evaluated to #f if its parameters represent the same object data in memory;

and

The scheme stores inaccurate numbers (1.1) differently than exact numbers (1)

Two arguments 1.1 are not in the same place in memory and return #f for eq?

Wikipedia Link

+3
source share

uh by numbers are unpredictable. This is before implementation or not, whether numeric literals are labeled so that the same numbers are in the same place in memory. For example, Racket recently chose to intern such literals while reading. http://www.mail-archive.com/ dev@racket-lang.org /msg04893.html

You will not know for sure whether the runtime of your language will unambiguously represent each number. This can affect the values ​​that are inserted into the box, for example, floats and bonuses. That is why = exists as a predicate for numbers: it checks the content is equal, not the pointer is evenly equal.

This does not apply to languages ​​like Scheme: equality vs equalness occurs in Python (is vs. ==), for example.

+3
source share

first difference: eq? works with any pair of values, and = works with any number of numbers.

There are several other equivalence predicates . Most of them accept only two parameters. = defined in the 'numbers

+1
source share

All Articles