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.0 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 BFCE0BBCA for ; Thu, 3 Apr 2008 16:25:32 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApoEAJuF9EfAXQIm/2dsb2JhbACsFw X-IronPort-AV: E=Sophos;i="4.25,599,1199660400"; d="scan'208";a="24557623" Received: from discorde.inria.fr ([192.93.2.38]) by mail4-smtp-sop.national.inria.fr with ESMTP; 03 Apr 2008 16:25:32 +0200 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id m33EPVO6021712 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Thu, 3 Apr 2008 16:25:32 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AsoBANeF9EcRlBBSmmdsb2JhbACRVwEBAQEBCAUJBxaaCA X-IronPort-AV: E=Sophos;i="4.25,599,1199660400"; d="scan'208";a="11029481" Received: from smtpoutm.mac.com ([17.148.16.82]) by mail3-smtp-sop.national.inria.fr with ESMTP; 03 Apr 2008 16:25:30 +0200 Received: from mac.com (asmtp010-s [10.150.69.73]) by smtpoutm.mac.com (Xserve/smtpout019/MantshX 4.0) with ESMTP id m33EPTVw026240 for ; Thu, 3 Apr 2008 07:25:29 -0700 (PDT) Received: from [192.168.8.107] (c-24-218-151-219.hsd1.ma.comcast.net [24.218.151.219]) (authenticated bits=0) by mac.com (Xserve/asmtp010/MantshX 4.0) with ESMTP id m33EPBIq017187 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO) for ; Thu, 3 Apr 2008 07:25:13 -0700 (PDT) Message-Id: <98127602-A30D-4910-9991-D4C9818185DE@mac.com> From: Gordon Henriksen To: caml-list@inria.fr In-Reply-To: <20080403140748.GA5408@fry> Content-Type: text/plain; charset=WINDOWS-1252; format=flowed; delsp=yes Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Apple Message framework v919.2) Subject: Re: [Caml-list] Unset or remove an OCaml callback registration Date: Thu, 3 Apr 2008 10:25:08 -0400 References: <3a360f590804021112r1cba67d9yc1715c08fb4a2e92@mail.gmail.com> <20080403.092612.89121596.garrigue@math.nagoya-u.ac.jp> <20080403140748.GA5408@fry> X-Mailer: Apple Mail (2.919.2) X-Miltered: at discorde with ID 47F4E8DB.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; unset:01 ocaml:01 ocaml:01 foo:01 foo:01 val:01 val:01 initialized:01 submodule:01 equality:01 wrote:01 wrote:01 caml-list:01 func:01 int:01 On Apr 3, 2008, at 10:07, Hezekiah M. Carty wrote: > On Thu, 03 Apr 2008, Jacques Garrigue wrote: > >> From: "Hezekiah M. Carty" >>> Is this possible, either from the C or OCaml side without making =20 >>> the callback associate with "foo" an option type (use =20 >>> (Callback.register "foo" (Some some_func)) to set a callback and =20 >>> (Callback.register "foo" None) to clear it)? >> >> Since Callback.register has type: string -> 'a -> unit you are not =20= >> 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 =20 >> you must initialize the value to 0 at program startup, because the =20= >> default for an unitialized value is 0 which is not Val_int(0)) > > If I wrap the C interface in an OCaml module, would it be enough to =20= > include: > > let () =3D Callback.register "foo" 0 > > in the top level of the module to have this command execute when the =20= > module is loaded? Or does the module user have to do some explicit =20= > initialization? I've used this technique, although I did have initialization ordering =20= problems. The outer module is not necessarily initialized before the =20 inner one. In my case, the initialization was idempotent, so I simply =20= repeated it in each submodule. =97 Gordon