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

From: Jos Koot (jos.koot at telefonica.net)
Date: Sun Jul 15 17:37:18 EDT 2007

No need to say sorry. Playing with Scheme seems a very good "sort of a past 
time" to me. It was your first sentence "I believe you can construct the syntax 
such that no extraneous variable need to be added" that made me wonder, read 
your post and respond.
Best wishes, Jos

----- Original Message ----- 
From: "Kyle Smith" <airfoil at bellsouth.net>
To: "Jos Koot" <jos.koot at telefonica.net>; <plt-scheme at list.cs.brown.edu>
Sent: Sunday, July 15, 2007 11:29 PM
Subject: Re: [plt-scheme] How to execute code in an environment other than it 
,isdefined?


> Hi Jos,
>
> I like your case-lambda solution even better.   I didn't mean to implicate
> that you hadn't solve Grant's problem, I was just messing around with
> the code; sort of a past time of mine.  Sorry if it came across that way.
>
> Best wishes,
>
> --kyle
>
> Jos Koot wrote:
>> ----- 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:23 PM
>> Subject: Re: [plt-scheme] How to execute code in an environment other than it 
>> ,isdefined?
>>
>>
>>> Hi Grant and Jos,
>>>
>>> I believe you can construct the syntax such that no extraneous
>>> variable need to be added.
>>
>> What your mascro does can as well and simpler be done by a procedure.
>>
>> (define pick-from
>> (case-lambda
>>  ((proc to) (pick-from proc 1 to))
>>  ((proc from to) (iter proc from to)))
>>
>> A contract can be added to make sure that proc, from and to have the right 
>> types.
>>
>>> Check out my take on your syntax
>>> below.  I've also corrected for the annoying attribute of range
>>> that acts like a C `for' statement, in that if you specify a range
>>> of from 1 to 100, you actually get 1 to 99.  Finally, I added
>>> fenders and syntax/loc to provide for more specific error
>>> reporting.  You could also match on the lambda glyph, but
>>> they don't show up on the newsgroup well, so I left it out.
>>>
>>> (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))]
>>
>> "(lambda (y) ((lambda (var) expr) y))" can as well be written as
>> "(lambda (var) expr)"which can as well be written as:
>> "proc" as in the last two cases (and omitting the fender)
>>
>> As I understoor the question of Grant, he wanted to simplify
>> (pick-from (lambda (x) expr) from to)
>> such as to releave the user from typing "(lambda (" and ")" and another ")"
>>
>> Best wishes, Jos Koot
>>
>>>        [(_ (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))) 50 100)
>>> (pick-from even? 100)
>>> (pick-from odd? 100)
>>> (define triple? (lambda (a) (zero? (modulo a 3))))
>>> (pick-from triple? 100)
>>>
>>> Enjoy!
>>>
>>> --kyle
>>> airfoil at bellsouth dot net
>>> schemekeys.blogspot.com
>>> www.schemekeys.net
>>>
>>
> 



Posted on the users mailing list.