From: Marius Vollmer <mvo@zagadka.de>
Cc: guile-user@gnu.org
Subject: Re: Using (defined? foo) from C.
Date: 29 Mar 2003 12:31:19 +0100 [thread overview]
Message-ID: <87brzue7eg.fsf@zagadka.ping.de> (raw)
In-Reply-To: <Pine.BSF.4.51.0303281759210.47991@helena.whitefang.com>
Thamer Al-Harbash <tmh@whitefang.com> writes:
> Is there anyway to create a symbol SCM in C without defining it
> in the current environment?
Yes. Symbols are a data type of their own, independent of bindings,
environments and modules. You can use
scm_str2symbol ("foo")
in C to get the symbol with the name "foo". Symbols in turn are used
to name things in environments and modules, but they can be used for
other things as well.
> If not is there a way of passing a C string as a symbol name to do
> reflection with? I'm looking for something as simple as evaluating
> (defined? foo) where foo is variable and receive the boolean value
> back.
Try this (with a big comment that Guile should provide it itself,
damnit):
static SCM
false (void *unused1, SCM unused2, SCM unused3)
{
return SCM_BOOL_F;
}
static SCM
wrapped_scm_c_lookup (void *data)
{
return scm_c_lookup ((char *)data);
}
int
defined_p (char *str)
{
return !SCM_FALSEP (scm_internal_catch (SCM_BOOL_T,
wrapped_scm_c_lookup, str,
false, NULL));
}
The reason for this longwinded code is that scm_c_lookup either
returns a valid variable or throws an error. We did this to have a
simple way to lookup variables and at the same time handle unbound
variables in a consistent manner.
Clearly, there should also be a function that return SCM_BOOL_F when a
name is unbound, but we don't have that yet. It will appear when the
module system API as a whole, ahem, 'stabilizes'.
--
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3 331E FAF8 226A D5D4 E405
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
next prev parent reply other threads:[~2003-03-29 11:31 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-03-28 23:11 Using (defined? foo) from C Thamer Al-Harbash
2003-03-29 11:31 ` Marius Vollmer [this message]
2003-03-29 15:20 ` Thamer Al-Harbash
2003-04-26 11:01 ` Neil Jerram
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87brzue7eg.fsf@zagadka.ping.de \
--to=mvo@zagadka.de \
--cc=guile-user@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).