[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: function registered with scm_c_define_gsubr: how can i handle an opt

From: Mark H Weaver
Subject: Re: function registered with scm_c_define_gsubr: how can i handle an optional parameter?
Date: Fri, 15 Dec 2017 03:06:46 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux)

Hi Alex,

Alex Vong <address@hidden> writes:

> Oh, I didn't really think too much about this. I always thought immediate
> objects like SCM_EOL, SCM_BOOL_T, ..., SCM_UNDEFINED can be compared
> using '=='. Is this an implementation detail that I should not depend
> on?

That's right.  You should not rely on SCM being represented in any
particular way.  In C, '==' works only on pointers and values of
arithmetic type, not on structs or unions.  Therefore, in general, you
cannot use '==' on a value of an abstract type without some knowledge of
the underlying type.

Guile's API is designed to avoid propagating assumptions about the SCM
type.  Please use only the functions and macros in Guile's public API to
inspect, compare, or manipulate values of type SCM.  This will enable
Guile implementors and other hackers to experiment with other SCM data
representations.  We reserve the right to change the SCM type in future
versions of Guile (but not within a stable release series e.g. 2.2.x).

I should also mention that Guile provides a mechanism to check for such
mistakes.  If you test compiling your libguile-using code with
-DSCM_DEBUG_TYPING_STRICTNESS=2, it will change SCM to be a struct type,
and you'll get a compile error if you attempt to use '==' on values of
type SCM.  (Note that this will produce code that is ABI-incompatible
with libguile compiled using the default SCM_DEBUG_TYPING_STRICTNESS=1
setting, so typically you would set SCM_DEBUG_TYPING_STRICTNESS=2 only
as a compile-time check.)

For details, see the description of SCM_DEBUG_TYPING_STRICTNESS in
__scm.h, and also the top few pages of tags.h, which describes the
fundamental concepts of how Guile Scheme objects are represented in C,
including the definitions of the SCM type and the 'scm_is_eq' macro.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]