Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

lol MIT

Name: Anonymous 2011-01-18 11:18

Input: print 5 == 5.0

Output: True1

--
1Scheme (the initial language taught at MIT before Python) took type to an extreme. 5.0 and 5 were not considered equal because one was an integer and the other was a float. You weren’t even allowed to do (4 + 6.0.) Python is more rational – it treats the two values as equal.

Name: Anonymous 2011-01-18 11:37

>>1
(eq? 5 5.0)
Racket: #f
MIT/GNU Scheme: #f
Two objects are eq? when they are exactly the same. Strings are not eq?, an inexact number is not eq? to his exact counterpart. Two bignums and two characters with the same value may not be eq?.
It should be used for efficiency and symbol comparison (two symbols are always eq? unless one of the two is uninterned).

(eqv? 5 5.0)
Racket: #f
MIT/GNU Scheme: #f
Two objects are eqv? if they are also eq?, unless otherwise specified.
Two bignums and two characters are guaranteed to be eqv?, an inexact number is not the same of an exact number. It's the no-surprise does-what-expected strongly typed comparison function.
Two strings are, again, not eqv?.

(equal? 2 2.0)
Racket: #f
MIT/GNU Scheme: #f
Two objects are equal if they are also eqv?.
equal? should be used when you need to compare two objects that are not guaranteed to be eqv?, but with the same content. It's still strongly typed, so exact and inexact are not equal?.


(= 2 2.0)
(= 0.5 1/2)

Racket: #t
MIT/GNU Scheme: #t
Type specific comparison function, two numbers with the same value are =.

Have you read your SICP today, >>1?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List