* Using (defined? foo) from C.
@ 2003-03-28 23:11 Thamer Al-Harbash
2003-03-29 11:31 ` Marius Vollmer
0 siblings, 1 reply; 4+ messages in thread
From: Thamer Al-Harbash @ 2003-03-28 23:11 UTC (permalink / raw)
I'm attempting to do binding reflection with libguile from within
C. However, I cannot find a way to create a symbol without
defining it. There is no way to pass a C string to an equivalent
of scm_definedp() without using scm_define() to create the
symbol in the first place. A bit of a paradox :)
Is there anyway to create a symbol SCM in C without defining it
in the current environment? 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.
--
Thamer Al-Harbash http://www.whitefang.com/
(if (> pressure too-much-pressure)
'play-ac2 'work)
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Using (defined? foo) from C.
2003-03-28 23:11 Using (defined? foo) from C Thamer Al-Harbash
@ 2003-03-29 11:31 ` Marius Vollmer
2003-03-29 15:20 ` Thamer Al-Harbash
0 siblings, 1 reply; 4+ messages in thread
From: Marius Vollmer @ 2003-03-29 11:31 UTC (permalink / raw)
Cc: guile-user
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Using (defined? foo) from C.
2003-03-29 11:31 ` Marius Vollmer
@ 2003-03-29 15:20 ` Thamer Al-Harbash
2003-04-26 11:01 ` Neil Jerram
0 siblings, 1 reply; 4+ messages in thread
From: Thamer Al-Harbash @ 2003-03-29 15:20 UTC (permalink / raw)
Cc: guile-user
On Sat, 29 Mar 2003, Marius Vollmer wrote:
> 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")
Thanks, I couldn't find this in the procedure index of the manual
but it's mentioned in section 19.14 (transitioning to the scm
interface). That's exactly what I need.
--
Thamer Al-Harbash http://www.whitefang.com/
(if (> pressure too-much-pressure)
'play-ac2 'work)
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Using (defined? foo) from C.
2003-03-29 15:20 ` Thamer Al-Harbash
@ 2003-04-26 11:01 ` Neil Jerram
0 siblings, 0 replies; 4+ messages in thread
From: Neil Jerram @ 2003-04-26 11:01 UTC (permalink / raw)
Cc: Marius Vollmer
>>>>> "Thamer" == Thamer Al-Harbash <tmh@whitefang.com> writes:
Thamer> On Sat, 29 Mar 2003, Marius Vollmer wrote:
>> 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")
Thamer> Thanks, I couldn't find this in the procedure index of the
Thamer> manual but it's mentioned in section 19.14 (transitioning
Thamer> to the scm interface). That's exactly what I need.
If you have time, please could you work out the texinfo needed to get
this into the procedure index, and send a patch?
Many thanks,
Neil
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2003-04-26 11:01 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-03-28 23:11 Using (defined? foo) from C Thamer Al-Harbash
2003-03-29 11:31 ` Marius Vollmer
2003-03-29 15:20 ` Thamer Al-Harbash
2003-04-26 11:01 ` 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).