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

Lazy in racket

Name: Anonymous 2011-02-19 17:04

How2lazy in DrRacket?

There's the lazy library, but it's not functional, i.e. I define a to be 1, define b as a + a, force b, it gives 2, but then I force set a to be 5, and it gives b as 2 again.

Any way around this?

Name: Anonymous 2011-02-19 17:37

>>7
Or better:
(define-syntax (define-alias stx)
  (syntax-case stx ()
    ((~ id w)
     (identifier? #'w)
     #'(define-syntax id (make-rename-transformer #'w)))
    ((~ id w)
     #'(define-syntax (id stx)
         (syntax-case stx ()
           (b (identifier? #'b) #'w))))))

(define a 2)
(define-alias b (+ a 2))
b ; 4
(set! a 3)
b ; 5
(set! a 4)
b ; 6
(define-alias c a)
c ; 4
(set! a 3)
c ; 3

Name: Anonymous 2011-02-19 17:43

>>10
(define a 2)
(define-alias b (+ a 2))
(+ a b) ; 6
(set! a 3)
(+ a b) ; 8

It's just an example, though, don't do it.

As a function, you'd need to:
(define a 2)
(define (b) a)
(+ a (b))

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