unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: Matt Wette <matt.wette@gmail.com>
To: 31154@debbugs.gnu.org
Subject: bug#31154: predicate function for foreign-object not obvious
Date: Sat, 14 Apr 2018 11:33:59 -0700	[thread overview]
Message-ID: <689d625b-94f7-919b-c017-fa921d54c744@gmail.com> (raw)

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.
  






             reply	other threads:[~2018-04-14 18:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-14 18:33 Matt Wette [this message]
     [not found] ` <handler.31154.B.152373085729032.ack@debbugs.gnu.org>
2018-04-14 19:25   ` bug#31154: Acknowledgement (predicate function for foreign-object not obvious) Matt Wette

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=689d625b-94f7-919b-c017-fa921d54c744@gmail.com \
    --to=matt.wette@gmail.com \
    --cc=31154@debbugs.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).