2009/12/2 Richard Shann <richard.sh...@virgin.net>:
> 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?

If I understand you correctly, no. That's because the
thing going into eval-string can be arbitrarily complex --
e.g. (eval-string "(define foo (lambda (x) (+ x y))) (define (bar
z y) (foo (z)) (bar 2 2)")  and there's no particular way to know
if evaluating that won't throw some error. -- really, you have to
evaluate it to find out.

If you want to find out if some particular variable is bound
to a proceedure, you can try (proceedure? thing) see e.g.
http://www.gnu.org/software/guile/manual/html_node/Procedure-Properties.html

If you want to know if a variable is bound, try defined?  e.g.

guile> (defined? 'x)
#f
guile> (defined? (string->symbol "x"))
#f
guile> (define x 42)
guile> (defined? 'x)
#t
guile> (defined? (string->symbol "x"))
#t

--linas


--linas


Reply via email to