GNU bug report logs - #31154
predicate function for foreign-object not obvious

Previous Next

Package: guile;

Reported by: Matt Wette <matt.wette <at> gmail.com>

Date: Sat, 14 Apr 2018 18:35:01 UTC

Severity: normal

To reply to this bug, email your comments to 31154 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-guile <at> gnu.org:
bug#31154; Package guile. (Sat, 14 Apr 2018 18:35:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Matt Wette <matt.wette <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-guile <at> gnu.org. (Sat, 14 Apr 2018 18:35:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Matt Wette <matt.wette <at> gmail.com>
To: bug-guile <at> gnu.org
Subject: predicate function for foreign-object not obvious
Date: Sat, 14 Apr 2018 11:33:59 -0700
The reference manual (guile-2.2.3) does not provide instruction on how to generate
a predicate for a foreign object, and it is not obvious.  Maybe it doesn't need to
be in the manual but should then be in an example somewhere, IMO.

The following patch to the reference manual is one option:


--- doc/ref/api-foreign-objects.texi-orig	2018-04-14 11:26:35.779502997 -0700
+++ doc/ref/api-foreign-objects.texi	2018-04-14 11:28:42.823072217 -0700
@@ -96,6 +96,33 @@
 needed.
 @end deftypefn
 
+To generate a predicate for a foreign object use the @code{SCM_IS_A_P}
+macro as follows.
+
+@example
+static SCM foo_type;
+
+static SCM
+scm_foo_p(SCM obj) {
+  return SCM_IS_A_P(obj, foo_type)? SCM_BOOL_T: SCM_BOOL_F;
+}
+
+void
+init_foo()
+{
+  SCM name, slots;
+
+  name = scm_from_utf8_symbol("foo");
+  slots = scm_list_2 (scm_from_utf8_symbol ("data"),
+		      scm_from_utf8_symbol ("deps"));
+  finalizer = NULL;
+  foo_type = scm_make_foreign_object_type(name, slots, finalizer);
+
+  scm_c_define_gsubr("foo?", 1, 0, 0, scm_foo_p);
+  ...
+}
+@end example
+
 One can also access foreign objects from Scheme.  @xref{Foreign Objects
 and Scheme}, for some examples.
 





Information forwarded to bug-guile <at> gnu.org:
bug#31154; Package guile. (Sat, 14 Apr 2018 19:26:01 GMT) Full text and rfc822 format available.

Message #8 received at 31154 <at> debbugs.gnu.org (full text, mbox):

From: Matt Wette <matt.wette <at> gmail.com>
To: 31154 <at> debbugs.gnu.org
Subject: Re: bug#31154: Acknowledgement (predicate function for foreign-object
 not obvious)
Date: Sat, 14 Apr 2018 12:25:34 -0700
Perhaps it belongs with the demo in Section 5.5 Defining New Foreign Object Types,
with the image demo.





This bug report was last modified 7 years and 60 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.