From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Jon Wilson Newsgroups: gmane.lisp.guile.user Subject: Re: Newbie question: bind a variable on the fly Date: Sun, 11 Jun 2006 12:42:18 -0500 Message-ID: <448C55FA.4040708@fastmail.fm> References: <1149935144.4753.10.camel@encelade-dev3> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7BIT X-Trace: sea.gmane.org 1150048083 29764 80.91.229.2 (11 Jun 2006 17:48:03 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 11 Jun 2006 17:48:03 +0000 (UTC) Cc: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sun Jun 11 19:48:00 2006 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1FpU2O-0001MY-OG for guile-user@m.gmane.org; Sun, 11 Jun 2006 19:47:50 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FpU2O-00038b-1C for guile-user@m.gmane.org; Sun, 11 Jun 2006 13:47:48 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1FpU2J-00038Q-8c for guile-user@gnu.org; Sun, 11 Jun 2006 13:47:43 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1FpU2H-00038E-Ku for guile-user@gnu.org; Sun, 11 Jun 2006 13:47:42 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FpU2H-00038B-GG for guile-user@gnu.org; Sun, 11 Jun 2006 13:47:41 -0400 Original-Received: from [131.225.111.11] (helo=mailgw1.fnal.gov) by monty-python.gnu.org with esmtp (Exim 4.52) id 1FpUAp-0000NV-4D for guile-user@gnu.org; Sun, 11 Jun 2006 13:56:31 -0400 Original-Received: from mailav1.fnal.gov (mailav1.fnal.gov [131.225.111.18]) by mailgw1.fnal.gov (iPlanet Messaging Server 5.2 HotFix 2.06 (built Mar 28 2005)) with SMTP id <0J0P00C12IIAPQ@mailgw1.fnal.gov> for guile-user@gnu.org; Sun, 11 Jun 2006 12:42:11 -0500 (CDT) Original-Received: from mailgw1.fnal.gov ([131.225.111.11]) by mailav1.fnal.gov (SAVSMTP 3.1.7.47) with SMTP id M2006061112421126109 for ; Sun, 11 Jun 2006 12:42:11 -0500 Original-Received: from conversion-daemon.mailgw1.fnal.gov by mailgw1.fnal.gov (iPlanet Messaging Server 5.2 HotFix 2.06 (built Mar 28 2005)) id <0J0P00K01I7E4A@mailgw1.fnal.gov> (original mail from j85wilson@fastmail.fm) for guile-user@gnu.org; Sun, 11 Jun 2006 12:42:11 -0500 (CDT) Original-Received: from [64.53.130.230] (d53-64-230-130.nap.wideopenwest.com [64.53.130.230]) by mailgw1.fnal.gov (iPlanet Messaging Server 5.2 HotFix 2.06 (built Mar 28 2005)) with ESMTPSA id <0J0P0063DIIB06@mailgw1.fnal.gov>; Sun, 11 Jun 2006 12:42:11 -0500 (CDT) In-reply-to: <1149935144.4753.10.camel@encelade-dev3> Original-To: Vincent De Groote X-Accept-Language: en-us, en User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050324) 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:5342 Archived-At: Hi Vincent, Don't try this just yet. I want other people to give it a look-over and make sure it isn't foolish and dangerous before anybody lets it out in the wild. This doesn't use the exception, and it doesn't use a c function, and it doesn't do database lookups. However, it can be used anywhere (inside lets and lambdas) to set! a variable that hasn't been defined. It defines the variable at top level, and then sets it wherever you are. Note: it does establish a global binding rather than a local binding. This may or may not be what you want. I think that using this to establish a local binding would be an extremely difficult thing to do, as well as probably a bad idea. (define-macro (dyn-set! var val) `(begin (if (not (defined? (quote ,var))) (primitive-eval `(define ,(quote ,var) #f))) (set! ,var ,val))) (defined? 'undefined-symbol) ; => #f ;(set! undefined-symbol #t) Gives an error. (dyn-set! undefined-symbol #t) ; No error. (defined? 'undefined-symbol) ; => #t Regards, Jon Vincent De Groote wrote: > Hello, > > Is there a way to catch an "unbound-variable" exception, bind the > variable on the fly, and continue execution as if the exception didn't > occurs ? > > I'd like to catch this exception in a c function: the exception context > should be available, to retrieve the variable or function name. This > handler will lookup the value in a relational database. > > Is this possible ? > > > Thanks for you replies > > Vincent De Groote > > > > _______________________________________________ > Guile-user mailing list > Guile-user@gnu.org > http://lists.gnu.org/mailman/listinfo/guile-user _______________________________________________ Guile-user mailing list Guile-user@gnu.org http://lists.gnu.org/mailman/listinfo/guile-user