* scm_defined_p(sym, env)
@ 2011-08-23 11:36 Richard Shann
2011-08-23 11:54 ` rm
2011-08-29 11:30 ` rixed
0 siblings, 2 replies; 6+ messages in thread
From: Richard Shann @ 2011-08-23 11:36 UTC (permalink / raw)
To: guile-user
I have defined a function with one needed and one optional arg, using
scm_c_define_gsubr (name, 2, 0, 0, callback);
in my function I need to test if the second argument is present, it
looks like I need
scm_defined_p(sym, env)
but, if so, how do I find the value of env for the top-level
environment?
Richard Shann
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: scm_defined_p(sym, env)
2011-08-23 11:36 scm_defined_p(sym, env) Richard Shann
@ 2011-08-23 11:54 ` rm
2011-08-23 13:26 ` Richard Shann
2011-08-29 11:30 ` rixed
1 sibling, 1 reply; 6+ messages in thread
From: rm @ 2011-08-23 11:54 UTC (permalink / raw)
To: Richard Shann; +Cc: guile-user
On Tue, Aug 23, 2011 at 12:36:44PM +0100, Richard Shann wrote:
> I have defined a function with one needed and one optional arg, using
>
> scm_c_define_gsubr (name, 2, 0, 0, callback);
>
> in my function I need to test if the second argument is present, it
> looks like I need
>
> scm_defined_p(sym, env)
>
> but, if so, how do I find the value of env for the top-level
> environment?
Not shure I understand you here, Richard. Where would sym come from?
If your function looks like this:
(richards-function required-param an-optional-param)
thane your c function needs exactly two parameters:
ricks_c_func(SCM req, SCM opt) {
...
if (!SCM_UNBNDP (opt)) {
/* opt wasn't provided, so do something here */
}
...
}
Does that help?
Cheers, Ralf Mattes
> Richard Shann
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: scm_defined_p(sym, env)
2011-08-23 11:54 ` rm
@ 2011-08-23 13:26 ` Richard Shann
2011-08-23 19:07 ` Andreas Rottmann
0 siblings, 1 reply; 6+ messages in thread
From: Richard Shann @ 2011-08-23 13:26 UTC (permalink / raw)
To: rm; +Cc: guile-user
I didn't find the SCM_UNBNDP() that you mention but since mailing the
list I stumbled on SCM_UNDEFINED and tried
if(opt==SCM_UNDEFINED) ...
and that seems to work.
So (unless I am doing something bad) I think I am back on course -
thanks!
Richard
On Tue, 2011-08-23 at 13:54 +0200, rm@tuxteam.de wrote:
> On Tue, Aug 23, 2011 at 12:36:44PM +0100, Richard Shann wrote:
> > I have defined a function with one needed and one optional arg, using
> >
> > scm_c_define_gsubr (name, 2, 0, 0, callback);
> >
> > in my function I need to test if the second argument is present, it
> > looks like I need
> >
> > scm_defined_p(sym, env)
> >
> > but, if so, how do I find the value of env for the top-level
> > environment?
>
> Not shure I understand you here, Richard. Where would sym come from?
> If your function looks like this:
>
> (richards-function required-param an-optional-param)
>
> thane your c function needs exactly two parameters:
>
> ricks_c_func(SCM req, SCM opt) {
>
> ...
>
> if (!SCM_UNBNDP (opt)) {
> /* opt wasn't provided, so do something here */
> }
>
> ...
>
> }
>
>
> Does that help?
>
> Cheers, Ralf Mattes
>
> > Richard Shann
> >
>
> >
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: scm_defined_p(sym, env)
2011-08-23 13:26 ` Richard Shann
@ 2011-08-23 19:07 ` Andreas Rottmann
0 siblings, 0 replies; 6+ messages in thread
From: Andreas Rottmann @ 2011-08-23 19:07 UTC (permalink / raw)
To: richard.shann; +Cc: guile-user, rm
Richard Shann <richard.shann@virgin.net> writes:
> I didn't find the SCM_UNBNDP() that you mention but since mailing the
> list I stumbled on SCM_UNDEFINED and tried
> if(opt==SCM_UNDEFINED) ...
> and that seems to work.
>
IIRC, that this works is not actually guaranteed (it depends on the type
of the SCM values; that type might not have defined/reasonable behavior
wrt. the "==" operator, so the right way to write the above comparison
would be `scm_is_eq(opt, SCM_UNDEFINED)', and incidentially, this is how
SCM_UNBNDP() is defined (see libguile/tags.h, at least on Guile 2.0).
> So (unless I am doing something bad) I think I am back on course -
> thanks!
>
The idiom you used may work for you now, but may be broken at any time,
or even when compiling Guile with a different configuration (search for
SCM_DEBUG_TYPING_STRICTNESS in libguile/tags.h for illustration).
HTH, Rotty
PS: Please consider avoiding top-posts (see for instance
<http://www.usenet-replayer.com/faq/alt.games.generals.html> for a
rationale).
--
Andreas Rottmann -- <http://rotty.yi.org/>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: scm_defined_p(sym, env)
[not found] <mailman.191.1314201660.28460.guile-user@gnu.org>
@ 2011-08-24 20:25 ` Richard Shann
0 siblings, 0 replies; 6+ messages in thread
From: Richard Shann @ 2011-08-24 20:25 UTC (permalink / raw)
To: guile-user
Thanks for this, I see there is also scm_is_true to take care of the
possibility that SCM_BOOL_T might not be a scalar type, we should be
using that too.
Richard
On Wed, 2011-08-24 at 12:01 -0400, guile-user-request@gnu.org wrote:
>
> Richard Shann <richard.shann@virgin.net> writes:
>
> > I didn't find the SCM_UNBNDP() that you mention but since mailing
> the
> > list I stumbled on SCM_UNDEFINED and tried
> > if(opt==SCM_UNDEFINED) ...
> > and that seems to work.
> >
> IIRC, that this works is not actually guaranteed (it depends on the
> type
> of the SCM values; that type might not have defined/reasonable
> behavior
> wrt. the "==" operator, so the right way to write the above comparison
> would be `scm_is_eq(opt, SCM_UNDEFINED)', and incidentially, this is
> how
> SCM_UNBNDP() is defined (see libguile/tags.h, at least on Guile 2.0).
>
> > So (unless I am doing something bad) I think I am back on course -
> > thanks!
> >
> The idiom you used may work for you now, but may be broken at any
> time,
> or even when compiling Guile with a different configuration (search
> for
> SCM_DEBUG_TYPING_STRICTNESS in libguile/tags.h for illustration).
>
> HTH, Rotty
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: scm_defined_p(sym, env)
2011-08-23 11:36 scm_defined_p(sym, env) Richard Shann
2011-08-23 11:54 ` rm
@ 2011-08-29 11:30 ` rixed
1 sibling, 0 replies; 6+ messages in thread
From: rixed @ 2011-08-29 11:30 UTC (permalink / raw)
To: guile-user
-[ Tue, Aug 23, 2011 at 12:36:44PM +0100, Richard Shann ]----
> I have defined a function with one needed and one optional arg, using
>
> scm_c_define_gsubr (name, 2, 0, 0, callback);
You mean :
scm_c_define_gsubr (name, 1, 1, 0, callback);
don't you ?
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-08-29 11:30 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-23 11:36 scm_defined_p(sym, env) Richard Shann
2011-08-23 11:54 ` rm
2011-08-23 13:26 ` Richard Shann
2011-08-23 19:07 ` Andreas Rottmann
2011-08-29 11:30 ` rixed
[not found] <mailman.191.1314201660.28460.guile-user@gnu.org>
2011-08-24 20:25 ` Richard Shann
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).