[plt-scheme] How to execute code in an environment other than it ,isdefined?

From: Kyle Smith (airfoil at bellsouth.net)
Date: Sun Jul 15 16:48:54 EDT 2007

I just noticed an error in the third clause of pick-form,
and I went ahead and added the lambda glyph; maybe
it will show up on the web version correctly:

(module pick-from mzscheme
(require (lib "42.ss" "srfi"))
(provide pick-from)
(define (iter f from to)
(list-ec (:range x from (add1 to))
(if (f x))
x))
(define-syntax pick-from
(lambda (stx)
(syntax-case stx (λ lambda)
[(_ (λ (var) expr) from to)
(identifier? #'var)
(syntax/loc stx
(iter (lambda (y) ((lambda (var) expr) y)) from to))]
[(_ (λ (var) expr) to)
(identifier? #'var)
(syntax/loc stx
(iter (lambda (y) ((lambda (var) expr) y)) 1 to))]
[(_ (lambda (var) expr) from to)
(identifier? #'var)
(syntax/loc stx
(iter (lambda (y) ((lambda (var) expr) y)) from to))]
[(_ (lambda (var) expr) to)
(identifier? #'var)
(syntax/loc stx
(iter (lambda (y) ((lambda (var) expr) y)) 1 to))]
[(_ proc from to)
(identifier? #'proc)
(syntax/loc stx
(iter proc from to))]
[(_ proc to)
(identifier? #'proc)
(syntax/loc stx
(iter proc 1 to))]))))

(require pick-from)
(pick-from (lambda (a) (zero? (modulo a 3))) 66 99)
(pick-from (λ (a) (zero? (modulo a 5))) 75 100)
(pick-from even? 2 20)
(pick-from odd? 1 17)
(define triple? (lambda (a) (zero? (modulo a 10))))
(pick-from triple? 100)
=========================================
Welcome to DrScheme, version 370.3-svn9jun2007 [3m].
Language: SchemeKeys.
(66 69 72 75 78 81 84 87 90 93 96 99)
(75 80 85 90 95 100)
(2 4 6 8 10 12 14 16 18 20)
(1 3 5 7 9 11 13 15 17)
(10 20 30 40 50 60 70 80 90 100)

Thats better,

--kyle


Posted on the users mailing list.