Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between eq? and = in Scheme?

Tags:

scheme

racket

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

This is the interaction window in DrScheme. Could somebody please explain the difference between = and eq? in Scheme?

like image 837
unj2 Avatar asked Jun 02 '09 20:06

unj2


People also ask

What is EQ in scheme?

eq? is pointer comparison. It returns #t iff its arguments literally refer to the same objects in memory. Symbols are unique ('fred always evaluates to the same object). Two symbols that look the same are eq. Two variables that refer to the same object are eq.

How do you write not equal to in scheme?

Boolean operations: and, or, not Since Scheme doesn't have a numeric "not equals" operator (like the != operator in C/Java/Python), we have to combine not and = in order to evaluate "not equals".

What is scheme operator?

Scheme Operator means each person within an Outlet authorized by the Agent to operate SCHEME Services using the Equipment.

What is equality predicate?

Equality predicates tell whether one value is "the same as" another. There are actually several important senses of "the same as," so Scheme provides four equality predicates. Sometimes you want to know whether two data structures are structurally the same, with the same values in the same places.


1 Answers

= compares numbers. eq? tests if the parameters represent the same data object in memory. eqv? should work in the second case as it tests same as eq? but tests primitives specially. More on equlivence predicates in scheme here.

like image 104
JP Alioto Avatar answered Sep 28 '22 11:09

JP Alioto