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

Pages: 1-

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:24


(= 5 5.0)
#t


(+ 4 6.0)
10.0


racket ftw

Name: Anonymous 2011-01-18 11:27

$ sudo apt-get install plt-scheme
[sudo] password for xarn:
Reading package lists... Done
Building dependency tree      
Reading state information... Done
The following extra packages will be installed:
  plt-scheme-doc
The following NEW packages will be installed:
  plt-scheme plt-scheme-doc
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 45.2MB of archives.
After this operation, 252MB of additional disk space will be used.
Do you want to continue [Y/n]? n
Abort.
$

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?

Name: Anonymous 2011-01-18 11:39

>>3
$ sudo apt-get install plt-scheme
sudo: This is not ubuntu, faggot.

Name: Anonymous 2011-01-18 11:54

>>4
According to MIT Sick pea is ``extreme and not rational''

Name: Anonymous 2011-01-18 12:00

>>6
ONE WORD: CHUNKY BACON ^__^. THREAD OVER

Name: Anonymous 2011-01-18 12:11

>>3
Poor XARN, give me your webmoney address and I'll send you $0.20 so you can buy yourself the whole 252MB of additional disk space (based on current average price per HDD TB).

Name: Anonymous 2011-01-18 12:49

>>8
Actually, it would be around $0.03. You fucked up yo'ure calculation.

Name: Anonymous 2011-01-18 12:52

>>9
That's pretty cheap, like you're mom.

Name: Anonymous 2011-01-18 13:46

>>10
*yo'ure

Name: Anonymous 2011-01-18 13:49

Python is more floating
Fixed.

Name: Anonymous 2011-01-18 14:08

WARNING: BLOAT
#lang racket

(expand #'(and #f 1 2 3 4))
;; expands to:
; (if #f (if 1 (if 2 (if 3 4 #f) #f) #f)
;: should expand to:
; #f
;; Why?
;; Because #f is constant in that expression,
;;+there's no need to generate more code than
;;+needed.
;; If `and' encounters a constant #f during the
;;+expansion, it should just stop there.

(expand #'(or #t 1 2 3 4))
;; expands to:
; (let ((x #t))
;   (if x x
;       (let ((x 1))
;         ...)))
;; should expand to:
; #t
;; Why?
;; Read above, change `and' with `or' and `#f'
;;+with `#t'

(expand #'(and 1 2 3 #t 4 5))
;; expands to:
; (if 1 (if 2 (if 3 (if #t (if 4 5 #f) #f) #f) #f) #f)
;; should expand to:
; (if 1 (if 2 (if 3 (if 4 5 #f) #f) #f) #f)
;; Why?
;; A constant #t is, of course known to be true,
;;+evaluating it doesn't have any side effect, so
;;+that (if #t ... #f) can be optimised away.

(expand #'(or 1 #f 2 3))
;; expands to:
; (let ((x 1))
;   (if x x
;       (let ((x #f))
;         (if x x
;             (let ((x 2)) ...))))))
;; should expand to:
; (let ((x 1))
;   (if x x
;       (let ((x 2)) ...)))
;; Why?
;; Same as and.

;; These macros do the right thing.
(define-syntax (or stx)
  (syntax-case stx ()
    ((~) #'#f)
    ((~ #f t ...) #'(~ t ...))
    ((~ #t t ...) #'#t)
    ((~ t) #'(#%epression t))
    ((~ t r ...)
     #'(let ((x t))
         (if x x (~ r ...))))))

(define-syntax (and stx)
  (syntax-case stx ()
    ((~) #t)
    ((~ #t t ...) #'(~ t ...))
    ((~ #f t ...) #f)
    ((~ t) #'(#%expression t))
    ((~ t r ...)
     #'(if t (~ r ...) #f))))

Name: R6RS Guy 2011-01-18 15:21

OP, I don't know where you read that, or how you came to that
conclusion as it is not consistent with either my reading of the
R[56]RS or my experience of various scheme implementations.

5.0 and 5 were not considered equal because one was an integer and the other was a float.
This is incorrect, both are integers. The difference is in exactness,
specifically, the former is an inexact integer, and the latter is an
exact integer. Equality is a separate issue, and has been dealt with
be >>4. I'd also like to point out that Scheme has no notion of
a float[1] and that while floating point is the usual implementation
method for inexact arithmetic, it is not required to be that way[2][3].

You weren’t even allowed to do (4 + 6.0.)
If I were to be an asshole, I'd say that's because Scheme does not
support a 4 function, nor any form of infix arithmetic[4], and
6.0. is not a valid token in Scheme.
I think you'll find that (+ 4 6.0) is valid in both the R5RS and the
R6RS, and presumably in earlier versions of the report too. According
to the R5RS, + has the interface (+ z1 ...) [5], which means that
it
accepts 1 or more complex numbers[6] and as floating point numbers
are real?, they are also complex?, and therefore acceptable to
+.
R6RS saves you the bother of remembering a convention such as
"z = complex number", by explicitly stating that all arithmetic
procedures accept both exact and inexact arguments.[7]

The only way a standards-compliant Scheme could fail on that example
is if it did not support either exact arithmetic, or inexact
arithmetic at all[8], and that is very different from the type
mismatch you are implying.

>>2
racket ftw
Correct arithmetic is hardly specific to Racket, indeed it should only
be wrong in implementations like SSCM, SigScheme and Dream, as they do
not support inexact arithmetic[9].


[sub]--
1. http://trac.sacrideo.us/wg/wiki/NumericTower

--
1. Some could argue that the R6RS implies it by the (rnrs arithmetic
flonums) library, but it specifically states that a floating point
representation is not required. (see 3)

2. "An implementation may use floating point and other approximate
representation strategies for inexact numbers."

http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-9.html#%_sec_6.2.3

3. "Note that this does not imply that an implementation must use
floating-point representations."

http://www.r6rs.org/final/html/r6rs/r6rs-Z-H-6.html#node_sec_3.3


4. It can of course be added as a library, although I've never used
any of them. I'd assume they all work by having an infix keyword in
the operator position [so your would be (infix 4 + 6.0)], similary to
the way Marco Maggi's infix library works (https://github.com/marcomaggi/Infix).

5. http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-9.html#%_sec_6.2.5

6. "The following naming conventions also imply type restrictions:
<snipped>
z, z1, ... zj, ...    complex number"

http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-4.html#%_sec_1.3.3

7. "The procedures described here implement arithmetic that is generic
over the numerical tower described in chapter 3. The generic
procedures described in this section accept both exact and inexact
number objects as arguments, performing coercions and selecting the
appropriate operations as determined by the numeric subtypes of their
arguments."

http://www.r6rs.org/final/html/r6rs/r6rs-Z-H-14.html#node_sec_11.7

8. The R5RS explicitly allows an implementation to support less than
the full numeric tower,
"Implementations of Scheme are not required to implement the whole
tower of subtypes given in section 6.2.1, but they must implement a
coherent subset consistent with both the purposes of the
implementation and the spirit of the Scheme language."

http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-9.html#%_sec_6.2.3
whereas R6RS requires a full tower. See 9, for more thorough take on
tower support.

9. http://trac.sacrideo.us/wg/wiki/NumericTower
I know he'll never read this, but special thanks to John Cowan for his
excellent list gathering as part of the R7RS WG process.

Name: Anonymous 2011-01-18 15:38

>>14
see >>4

Name: Anonymous 2011-01-18 15:44

>>15
Yes, I know. I even referenced it. However, it did not address the mistake of claiming that (integer? 5.0) ; #f, or, more importantly, the claims about addition. Also, I was bored, and being a language lawyer is a fun distraction for 10 minutes.

Name: Anonymous 2011-01-18 15:54

>>14
Dream
I thought no one knew it even exists.

By the way, what do you think about >>13, is that optimisation standard compliant or did I get something wrong?

Name: Anonymous 2011-01-18 16:25

>>17
Your macros aresn't, because you use Racket's magic macros (or whatever they call them) and a common but non-standard define-syntax extension, but the optimisation would be fine (indeed it could be extended to include numbers, strings, etc). Making those trivial changes would give us

(define-syntax or
  (lambda (stx)
    (syntax-case stx ()
    ((~) #'#f)
    ((~ #f t ...) #'(~ t ...))
    ((~ #t t ...) #'#t)
    ((~ t) #'t)
    ((~ t r ...)
     #'(let ((x t))
         (if x x (~ r ...)))))))

(define-syntax and
  (lambda (stx)
    (syntax-case stx ()
    ((~) #'#t)
    ((~ #t t ...) #'(~ t ...))
    ((~ #f t ...) #'#f)
    ((~ t) #'t)
    ((~ t r ...)
     #'(if t (~ r ...) #f)))))

and this would be portable+standards-compliant. Using syntax-rules would make it portable to R5RS too.

Name: Anonymous 2011-01-18 16:58

>>18
Racket's magic macros
Oh, yeah, you mean the #%expression thing? I forgot about it. It's not necessary, it's there to just make define-like forms fail.

a common but non-standard define-syntax extension
(define-syntax (id stx) ...) instead of (define-syntax id (lambda (stx) ...))?

and this would be portable+standards-compliant.
AFAIK #' is non-standard.

Using syntax-rules would make it portable to R5RS too.
I would use syntax-rules, but it gave me an error (quite strange, actually: # reference to an identifier before its definition: ~, where ~ should be the syntax of the macro. With syntax-case just works.)

Name: Anonymous 2011-01-18 17:05

Name: Anonymous 2011-01-18 17:12

>>19
(define-syntax (id stx) ...) instead of (define-syntax id (lambda (stx) ...))?
yes

AFAIK #' is non-standard.
It was added in R6RS
http://www.r6rs.org/final/html/r6rs/r6rs-Z-H-7.html#node_sec_4.3.5

I would use syntax-rules, but it gave me an error
AFAICS, the standard allows it, but the Racket documentation for syntax-rules in the Reference is pretty explicit that each generated-id binds no identifier in the corresponding template.
http://docs.racket-lang.org/reference/stx-patterns.html?q=syntax-rules#%28form._%28%28lib._racket/private/stxcase-scheme..rkt%29._syntax-rules%29%29

Name: Anonymous 2011-01-31 19:45

<-- check em dubz

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