Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Re: Utilisation de
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 1996-07-05 (19:14)
From: Jun P. Furuse <furuse@k...>
Subject: Re: Utilisation de

> 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

 	let g = fun t -> t
	  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

	let rt = ref None in
	let g = function Some t -> ....
		       | None -> .... 
	  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

Yours sincerely,
Jun P. Furuse		      | Research Institute for Mathematical Sciences
( | Kyoto University, Japan