From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: hcarty@atmos.umd.edu
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Unset or remove an OCaml callback registration
Date: Thu, 03 Apr 2008 09:26:12 +0900 (JST) [thread overview]
Message-ID: <20080403.092612.89121596.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <3a360f590804021112r1cba67d9yc1715c08fb4a2e92@mail.gmail.com>
From: "Hezekiah M. Carty" <hcarty@atmos.umd.edu>
> Is it possible to unregister a function or other value registered with
> Callback.register? I use (Callback.register "foo" some_func) to
> register coordinate transforms for a C library. If no callback is
> registered for "foo" then a default transform is used by the C
> library. I would like to be able to set and then remove the
> association of some_func to the name "foo" at various points in my
> program so that the C code will fall back on the default transform
> (which does not require a callback and is much faster) when the named
> callback "foo" is undefined or has been unregistered.
>
> Is this possible, either from the C or OCaml side without making the
> callback associate with "foo" an option type (use (Callback.register
> "foo" (Some some_func)) to set a callback and (Callback.register "foo"
> None) to clear it)?
Since Callback.register has type: string -> 'a -> unit
you are not limited by the ocaml type system.
So you can reset your value with
Callback.register "foo" 0
and check for equality with Val_int(0) on the C side.
(Note that you must initialize the value to 0 at program startup,
because the default for an unitialized value is 0 which is not
Val_int(0))
Jacques Garrigue
next prev parent reply other threads:[~2008-04-03 0:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-02 18:12 Hezekiah M. Carty
2008-04-03 0:26 ` Jacques Garrigue [this message]
2008-04-03 14:07 ` [Caml-list] " Hezekiah M. Carty
2008-04-03 14:25 ` Gordon Henriksen
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080403.092612.89121596.garrigue@math.nagoya-u.ac.jp \
--to=garrigue@math.nagoya-u.ac.jp \
--cc=caml-list@inria.fr \
--cc=hcarty@atmos.umd.edu \
/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 NNTP newsgroup(s).