[plt-scheme] How to execute code in an environment other than it ,isdefined?
Hi Jos,
Yeah, it would have to be extended to match let forms. But if I
omit the first two cases, on my machine, it doesn't match the λ
glyph.
Welcome to DrScheme, version 370.3-svn9jun2007 [3m].
Language: SchemeKeys.
(66 69 72 75 78 81 84 87 90 93 96 99)
#<struct:object:...pper/stepper-tool.ss:618:8>:38:0: pick-from: bad
syntax in: (pick-from (λ (a) (zero? (modulo a 5))) 75 100) in:
(pick-from (λ (a) (zero? (modulo a 5))) 75 100)
But your right, if I remove them from the literals list, they match.
That's nice to know. Thanks for pointing that out.
Enjoy!
--kyle
Jos Koot wrote:
> I forgot to say that your pick-from does not work for:
> (pick-from (let ( ) even?) 1 100)
> It would if you omit the fenders, but then the first two cases of the
> macro are superfluous.
> Jos
>
> ----- Original Message ----- From: "Kyle Smith" <airfoil at bellsouth.net>
> To: <plt-scheme at list.cs.brown.edu>; <grettke at acm.org>;
> <jos.koot at telefonica.net>
> Sent: Sunday, July 15, 2007 10:48 PM
> Subject: Re: [plt-scheme] How to execute code in an environment other
> than it ,isdefined?
>
>
>> 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
>>
>