From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.6.10/8.6.6) id VAA08774 for caml-redistribution; Fri, 5 Jul 1996 21:14:24 +0200 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.6.10/8.6.6) with ESMTP id TAA07838 for ; Fri, 5 Jul 1996 19:55:39 +0200 Received: from choshi.kaba.or.jp (root@choshi.kaba.or.jp [192.51.37.14]) by concorde.inria.fr (8.7.1/8.7.1) with SMTP id TAA07977 for ; Fri, 5 Jul 1996 19:55:30 +0200 (MET DST) Received: from choshi.kaba.or.jp by choshi.kaba.or.jp (8.6.12+2.5Wb7/2.8Wb-kaba) id CAA28373; Sat, 6 Jul 1996 02:49:18 +0900 Message-Id: <199607051749.CAA28373@choshi.kaba.or.jp> To: henry@kelenn-gw.univ-brest.fr (licence informatique) Cc: caml-list@pauillac.inria.fr Subject: Re: Utilisation de In-reply-to: Your message of Thu, 04 Jul 1996 17:17:37 +0200. <199607041517.RAA02101@kelenn-gw.univ-brest.fr> Date: Sat, 06 Jul 1996 02:54:31 +0900 From: "Jun P. Furuse" Sender: weis > J'utilise CamlTk 4.0 (version mai 96) > > Je souhaite utiliser une fonction retournant une valeur avec l'option Command > dans un menu; > > par exemple : > menu__add_command m [Label "Essai"; Command (let t = f(n))]; > > Il s'avere que cette instruction ne fonctionne pas car, l'option Command > accepte que les fonctions de type unit -> unit; > > Est-il possible de resoudre ce probleme sans utiliser des variables globales > mutables ? I am sorry that my answer is in English. I just started learning French, and I probably understand your question, but it is difficult to answer in French for me ;-). I think this is impossible. In general event driven programming, you can not define values in callback functions and export them out of the functions. let g = fun t -> t in menu__add_command m [Label "Essai"; Command (let t = f(n))]; ...; g t Of course it is wrong syntax. But even if it were correct, the value 't' will not be defined until the command is invoked. So the application of t for g will not be evaluated correctly unless the command is called before it. You must use mutable values to export values out of callbacks. For example: let rt = ref None in let g = function Some t -> .... | None -> .... in menu__add_command m [Label "Essai"; Command (rt := Some (f n))]; ...; g !rt Not only references, you can also use mutable record fields or Tk's textvariables as mutable values. But if you do not want to such mutable values, you must do everything which needs t in the callback function. Yours sincerely, ----------------------------------------------------------------------------- Jun P. Furuse | Research Institute for Mathematical Sciences (furuse@kurims.kyoto-u.ac.jp) | Kyoto University, Japan