unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* A variable that holds a string which may be the name of a variable.
@ 2009-12-02 19:22 Richard Shann
  2009-12-02 22:19 ` Neil Jerram
  2009-12-02 22:37 ` Linas Vepstas
  0 siblings, 2 replies; 8+ messages in thread
From: Richard Shann @ 2009-12-02 19:22 UTC (permalink / raw)
  To: guile-user

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!

Richard Shann






^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: A variable that holds a string which may be the name of a variable.
@ 2009-12-03 16:11 Richard Shann
  2009-12-03 18:52 ` Neil Jerram
  0 siblings, 1 reply; 8+ messages in thread
From: Richard Shann @ 2009-12-03 16:11 UTC (permalink / raw)
  To: guile-user

Thanks to all guileans who have responded. I seem to have a workable
solution based on Neil's code. The thing I hadn't grokked was the
existence of the with-input-from-string procedure. I had been messing
with defined? and symbol? but got nowhere.

FWIW the core bit of code I ended up with takes the name of a command,
<name> and looks for a string in a variable called Help-d-<name> if it
exists:

(set! help (string-append "Help-d-" name))	  
	  (let ((sym (with-input-from-string help read)))
	    (if (defined? sym)
		(set! help (eval sym (current-module)))
		(set! help "No help")
		))

This seems to cover all the cases. I haven't really got to the bottom of
what that with-input-from-string procedure does - I got as far as the
documentation for read which mentions an s-expression. Elsewhere I have
seen references to "forms", perhaps there is something establishing some
basic terminology that I have missed...

But thanks a lot - I am on my way again...

Richard







^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2009-12-03 19:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-02 19:22 A variable that holds a string which may be the name of a variable Richard Shann
2009-12-02 22:19 ` Neil Jerram
2009-12-03 17:23   ` Linas Vepstas
2009-12-03 18:56     ` Neil Jerram
2009-12-03 19:00       ` Richard Shann
2009-12-02 22:37 ` Linas Vepstas
  -- strict thread matches above, loose matches on Subject: below --
2009-12-03 16:11 Richard Shann
2009-12-03 18:52 ` Neil Jerram

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).