#lang racket (define-namespace-anchor a) (define ns (namespace-anchor->namespace a)) ; Omega -- expresie nereductibilă ;( (λ (x) 5) ((λ (x) (x x)) (λ (x) (x x)))) ;; clasic (define prod1 (λ (x y) (displayln "prod") (if x (* y (+ y 1)) 0))) (define test1 (λ (x) (let ((y 5)) (prod1 x (and (display "y ") y))))) (test1 #f) (test1 #t) (displayln "------ ^ direct") ;; quote + eval (define prod2 (λ (x y) (displayln "prod") (if x (* (eval y ns) (+ (eval y ns) 1)) 0))) ; eval necesită un spațiu de nume în care să evalueze expresia ; aici, am dat spațiul de nume global; o soluție ar fi să transmitem și spațiul de nume ca argument (define test2 (λ (x) (let ((y 5)) (prod2 x (quote (and (display "y ") y)))))) ;(test2 #f) (test2 #t) (displayln "------ ^ quote & eval") ;; inchidere λ (define prod3 (λ (x y) (displayln "prod") (if x (* (y) (+ (y) 1)) 0))) (define test3 (λ (x) (let ((y 5)) (prod3 x (λ () (and (display "y ") y)))))) (test3 #f) (test3 #t) (displayln "------ ^ închideri λ") ;; promisiuni (define prod4 (λ (x y) (displayln "prod") (if x (* (force y) (+ (force y) 1)) 0))) (define test4 (λ (x) (let ((y 5)) (prod4 x (delay (begin (display "y ") y)))))) (test4 #f) (test4 #t) (displayln "------ ^ promisiuni") (define y 2) (delay (and (display "y ") y)) ; -> prim rang