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 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.

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