From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andrew Gwozdziewycz Newsgroups: gmane.lisp.guile.user Subject: Re: progv in scheme Date: Tue, 13 Sep 2011 10:25:59 -0400 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1315924225 31940 80.91.229.12 (13 Sep 2011 14:30:25 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 13 Sep 2011 14:30:25 +0000 (UTC) Cc: guile-user@gnu.org To: Panicz Maciej Godek Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Tue Sep 13 16:30:21 2011 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1R3U0C-00069F-Bm for guile-user@m.gmane.org; Tue, 13 Sep 2011 16:30:20 +0200 Original-Received: from localhost ([::1]:39673 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R3U0B-0007FN-Hx for guile-user@m.gmane.org; Tue, 13 Sep 2011 10:30:19 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:46750) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R3U01-0007CO-95 for guile-user@gnu.org; Tue, 13 Sep 2011 10:30:18 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R3Tzr-0004yX-Pf for guile-user@gnu.org; Tue, 13 Sep 2011 10:30:09 -0400 Original-Received: from mail-qy0-f176.google.com ([209.85.216.176]:58928) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R3Tzr-0004yS-G6 for guile-user@gnu.org; Tue, 13 Sep 2011 10:29:59 -0400 Original-Received: by qyk36 with SMTP id 36so543217qyk.0 for ; Tue, 13 Sep 2011 07:29:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=tXAlpbqec22wS5QABKyvLF0+uPMpR+Bc2v3xgdekWXo=; b=KwX6gmfP0VMdsq7Kz+7HRULSC8B3D9YqOhc/WBmu4LHtsUKgGPOb9ty/e+iWJRf/b9 QA2joBmm+DSyIg6zQJoBYgBKmG1aOXGCd71AN0k3A8CLiH1UNVZCOnydlJNZm5vWZE+h SW+a2tDGs8/IRuMdD9RGJY3TpgbyTqT0P/w+s= Original-Received: by 10.68.35.227 with SMTP id l3mr3501265pbj.144.1315923959239; Tue, 13 Sep 2011 07:25:59 -0700 (PDT) Original-Received: by 10.142.144.6 with HTTP; Tue, 13 Sep 2011 07:25:59 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.216.176 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:8779 Archived-At: On Tue, Sep 13, 2011 at 9:54 AM, Panicz Maciej Godek wrote: > Hello, > Is there any clever way of binding values to the list of unknown > symbols in scheme? > > In common lisp there is a form "progv" that takes the list of symbols > and their corresponding values and binds them within the body of > progv. > > It is possible to do it using eval, like this: > (define (bind-and-eval symbols values body) > (eval `((lambda ,symbols ,body) . ,values) > =C2=A0 =C2=A0 =C2=A0(interaction-environment))) > (define-syntax let-symbols > (syntax-rules () > =C2=A0((_ symbols values (body ...)) > =C2=A0 (bind-and-eval symbols values (quote (body ...)))))) > > but using eval for this just seems too heavy. Is there any way of > doing it that would be more legal? > > Best regards, > M. Seems likely that you could use `syntax-case' to create a `let` out of thes= e: (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" Hope this helps! Andrew --=20 http://www.apgwoz.com