From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.1 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 37E06BBCA for ; Thu, 3 Apr 2008 02:26:31 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApoEAJDA80fAXQIm/2dsb2JhbACsMQ X-IronPort-AV: E=Sophos;i="4.25,596,1199660400"; d="scan'208";a="24526963" Received: from discorde.inria.fr ([192.93.2.38]) by mail4-smtp-sop.national.inria.fr with ESMTP; 03 Apr 2008 02:26:30 +0200 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id m330QSQa023631 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Thu, 3 Apr 2008 02:26:30 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApoEAJDA80eCNhAB/2dsb2JhbACsMQ X-IronPort-AV: E=Sophos;i="4.25,596,1199660400"; d="scan'208";a="9126379" Received: from kurims.kurims.kyoto-u.ac.jp ([130.54.16.1]) by mail2-smtp-roc.national.inria.fr with ESMTP; 03 Apr 2008 02:26:26 +0200 Received: from localhost (orion [130.54.16.5]) by kurims.kurims.kyoto-u.ac.jp (8.13.8/8.13.8) with ESMTP id m330QL0r029447; Thu, 3 Apr 2008 09:26:21 +0900 (JST) Date: Thu, 03 Apr 2008 09:26:12 +0900 (JST) Message-Id: <20080403.092612.89121596.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 From: Jacques Garrigue In-Reply-To: <3a360f590804021112r1cba67d9yc1715c08fb4a2e92@mail.gmail.com> References: <3a360f590804021112r1cba67d9yc1715c08fb4a2e92@mail.gmail.com> X-Mailer: Mew version 4.2 on Emacs 22.1 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 47F42434.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; unset:01 ocaml:01 foo:01 foo:01 ocaml:01 val:01 val:01 unregistered:98 equality:01 caml-list:01 undefined:01 func:01 func:01 int:01 int:01 From: "Hezekiah M. Carty" > 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