From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Neil Jerram Newsgroups: gmane.lisp.guile.user Subject: Re: A variable that holds a string which may be the name of a variable. Date: Wed, 02 Dec 2009 22:19:56 +0000 Message-ID: <87skbt81df.fsf@ossau.uklinux.net> References: <1259781727.3060.16.camel@debianrts.home> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1259797250 13427 80.91.229.12 (2 Dec 2009 23:40:50 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 2 Dec 2009 23:40:50 +0000 (UTC) Cc: guile-user@gnu.org To: richard.shann@virgin.net Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Thu Dec 03 00:40:43 2009 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 1NFyoM-00046A-1q for guile-user@m.gmane.org; Thu, 03 Dec 2009 00:40:42 +0100 Original-Received: from localhost ([127.0.0.1]:47757 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NFyoL-0002aE-MP for guile-user@m.gmane.org; Wed, 02 Dec 2009 18:40:41 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NFxYO-0007Jk-AA for guile-user@gnu.org; Wed, 02 Dec 2009 17:20:08 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NFxYJ-0007CF-4v for guile-user@gnu.org; Wed, 02 Dec 2009 17:20:07 -0500 Original-Received: from [199.232.76.173] (port=56969 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NFxYI-0007Bv-O3 for guile-user@gnu.org; Wed, 02 Dec 2009 17:20:02 -0500 Original-Received: from mail3.uklinux.net ([80.84.72.33]:55463) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NFxYH-0002ls-5u for guile-user@gnu.org; Wed, 02 Dec 2009 17:20:01 -0500 Original-Received: from arudy (host86-145-153-90.range86-145.btcentralplus.com [86.145.153.90]) by mail3.uklinux.net (Postfix) with ESMTP id 59CF21F6926; Wed, 2 Dec 2009 22:20:00 +0000 (GMT) Original-Received: from arudy (arudy [127.0.0.1]) by arudy (Postfix) with ESMTP id 8657A38023; Wed, 2 Dec 2009 22:19:56 +0000 (GMT) In-Reply-To: <1259781727.3060.16.camel@debianrts.home> (Richard Shann's message of "Wed, 02 Dec 2009 19:22:07 +0000") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.4-2.6 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:7513 Archived-At: Richard Shann writes: > I am stuck on one of those symbol/variable-name-in-a-string things > again: > > (define mything "display") > (display (eval-string mything)) > > that's fine. But can I test that the string in mything is the name of a > variable before doing the eval-string and finding out the hard way? I've > been doing (symbol? mything) etc, and going witless. Do I have to do all > that catch stuff? > > The situation is that I can guess (programmatically construct that is) > the name of the variable, but it may not be defined. If it isn't I will > just say so, but if it is I want the string it is defined to hold. > > Any help much appreciated! Hi Richard... :-) You can use defined? to find out if an arbitrary symbol is defined (in the current module). It takes a symbol, so for example: (let ((sym (with-input-from-string mything read))) (if (defined? sym) (eval sym (current-module)) (display "Sorry, that isn't defined"))) Does that help? Regards, Neil