guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: progv in scheme


From: Andrew Gwozdziewycz
Subject: Re: progv in scheme
Date: Tue, 13 Sep 2011 12:35:56 -0400

On Tue, Sep 13, 2011 at 12:04 PM, Panicz Maciej Godek
<address@hidden> wrote:
> 2011/9/13, Andrew Gwozdziewycz <address@hidden>:
>>
>> Seems likely that you could use `syntax-case' to create a `let` out of
>> these:
>>
>> (define-syntax progv
>>   (lambda (stx)
>>     (define (create-bindings syms vals)
>>       (datum->syntax stx (zip (syntax->datum syms) (syntax->datum vals))))
>>     (syntax-case stx ()
>>       ((_ symbols values body ...)
>>        (with-syntax ((bindings (create-bindings #'symbols #'values)))
>>           #'(let bindings
>>                (begin body ...)))))))
>>
>>
>>
>> ;; usage
>> (progv (foo bar baz) (1 2 3)
>>    (format (current-output-port) "Values: ~a ~a ~a\n" foo bar baz))
>> ;; output: "Values: 1 2 3"
>
> Hey,
> thanks for this code, maybe one day I will be able to comprehend it :)
> for now, the problem is that I want to bind the variables that are
> contained within a list, and that I don't know what's in that list.
>
> So, the following code should work as well:
> (let ((s '(foo bar baz))
>      (v '(1 2 3)))
>  (progv s v
>     (+ foo bar baz)))
> ===> 6

Ah, yes. I believe there's no way around using eval here. The
difficulty of course is compile time vs. runtime.


-- 
http://www.apgwoz.com



reply via email to

[Prev in Thread] Current Thread [Next in Thread]