From: "Jun P. Furuse" <furuse@kaba.or.jp>
To: henry@kelenn-gw.univ-brest.fr (licence informatique)
Cc: caml-list@pauillac.inria.fr
Subject: Re: Utilisation de
Date: Sat, 06 Jul 1996 02:54:31 +0900 [thread overview]
Message-ID: <199607051749.CAA28373@choshi.kaba.or.jp> (raw)
In-Reply-To: Your message of Thu, 04 Jul 1996 17:17:37 +0200. <199607041517.RAA02101@kelenn-gw.univ-brest.fr>
> 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
prev parent reply other threads:[~1996-07-05 19:14 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-07-04 15:17 licence informatique
1996-07-05 17:44 ` Francois Rouaix
1996-07-05 17:54 ` Jun P. Furuse [this message]
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=199607051749.CAA28373@choshi.kaba.or.jp \
--to=furuse@kaba.or.jp \
--cc=caml-list@pauillac.inria.fr \
--cc=henry@kelenn-gw.univ-brest.fr \
/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