From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Kjetil S. Matheussen" Newsgroups: gmane.lisp.guile.user Subject: Re: Injecting variables into closures. Date: Thu, 29 Nov 2007 15:44:50 +0100 (CET) Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Trace: ger.gmane.org 1196347565 13305 80.91.229.12 (29 Nov 2007 14:46:05 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 29 Nov 2007 14:46:05 +0000 (UTC) Cc: guile-user@gnu.org To: "Kjetil S. Matheussen" Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Thu Nov 29 15:46:12 2007 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1IxkeZ-00029n-Uv for guile-user@m.gmane.org; Thu, 29 Nov 2007 15:46:12 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IxkeK-0003Tp-A0 for guile-user@m.gmane.org; Thu, 29 Nov 2007 09:45:56 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IxkdP-00033c-QV for guile-user@gnu.org; Thu, 29 Nov 2007 09:44:59 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IxkdL-0002yR-MN for guile-user@gnu.org; Thu, 29 Nov 2007 09:44:59 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IxkdL-0002y2-En for guile-user@gnu.org; Thu, 29 Nov 2007 09:44:55 -0500 Original-Received: from mail-forward.uio.no ([129.240.10.42]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1IxkdK-0005C2-TX for guile-user@gnu.org; Thu, 29 Nov 2007 09:44:55 -0500 Original-Received: from mail-mx4.uio.no ([129.240.10.45]) by pat.uio.no with esmtp (Exim 4.67) (envelope-from ) id 1IxkdJ-0000HD-KB for guile-user@gnu.org; Thu, 29 Nov 2007 15:44:53 +0100 Original-Received: from bjo1-1x-dhcp290.studby.uio.no ([193.157.245.38]) by mail-mx4.uio.no with esmtps (TLSv1:AES256-SHA:256) (Exim 4.67) (envelope-from ) id 1IxkdJ-0006aZ-0X; Thu, 29 Nov 2007 15:44:53 +0100 X-X-Sender: kjetil@ttleush In-Reply-To: X-UiO-ClamAV-Virus: No X-UiO-Spam-info: not spam, SpamAssassin (score=-0.0, required=12.0, autolearn=disabled, AWL=-0.026) X-UiO-Scanned: 589D911E0269A5079DBEF50CC7161F799B6DACC3 X-UiO-SPAM-Test: remote_host: 193.157.245.38 spam_score: 0 maxlevel 200 minaction 1 bait 0 mail/h: 2 total 536 max/h 6 blacklist 0 greylist 0 ratelimit 0 X-detected-kernel: by monty-python.gnu.org: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:6303 Archived-At: On Thu, 29 Nov 2007, Kjetil S. Matheussen wrote: > > Hi, > > I need (well) to inject variables into closures, and have > come up with the following macro to do so: > > (define-macro (inject-variable name value) ... > (cond ((null? (cdr ,env)) ... > ((null? (null? (cdr (car ,env)))) #@^%$^&#! (define-macro (inject-variable name value) (define env (gensym)) (define closure (gensym)) (define vars (gensym)) (define secondname (gensym)) (define secondval (gensym)) (define first-env (gensym)) `((procedure->macro (lambda (,(gensym) ,env) (define ,first-env (car ,env)) (cond ((null? (cdr ,env)) (let ((,closure ,first-env)) (set-car! ,env (cons ',name ,value)) (set-cdr! ,env (list ,closure)))) ((not (pair? (cdr ,first-env))) (let* ((,vars ,first-env) (,secondname (car ,vars)) (,secondval (cdr ,vars))) (set-car! ,env (list (list ',name ,secondname) ,value ,secondval)))) (else (set-cdr! ,first-env (cons ,value (cdr ,first-env))) (set-car! ,first-env (cons ',name (car ,first-env))) (set-car! ,env ,first-env))))))) Sorry. :-) _______________________________________________ Guile-user mailing list Guile-user@gnu.org http://lists.gnu.org/mailman/listinfo/guile-user