From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id XAA16234; Mon, 1 Apr 2002 23:02:31 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id XAA18022 for caml-list@pauillac.inria.fr; Mon, 1 Apr 2002 23:02:30 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id VAA00663 for ; Sun, 31 Mar 2002 21:05:26 +0200 (MET DST) Received: from postfix1-2.free.fr (postfix1-2.free.fr [213.228.0.130]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g2VJ5PD17555 for ; Sun, 31 Mar 2002 21:05:25 +0200 (MET DST) Received: from gregoire.dijon.fr (grenoble-1-a7-75-184.dial.proxad.net [62.147.75.184]) by postfix1-2.free.fr (Postfix) with ESMTP id 2B421AB1E3; Sun, 31 Mar 2002 21:02:15 +0200 (CEST) Received: from gregoire (localhost [127.0.0.1]) by gregoire.dijon.fr (8.11.2/8.11.2/SuSE Linux 8.11.1-0.5) with SMTP id g2VIxbL08380; Sun, 31 Mar 2002 20:59:37 +0200 Date: Sun, 31 Mar 2002 20:59:37 +0200 From: Michel Quercia To: Attila Kondacs Cc: caml-list@inria.fr Subject: Re: [Caml-list] native-code and byte-code compiler differences Message-Id: <20020331205937.295fa6f5.michel.quercia@prepas.org> In-Reply-To: References: X-Mailer: Sylpheed version 0.7.2 (GTK+ 1.2.10; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Le Fri, 29 Mar 2002 16:00:41 -0500 (EST) Attila Kondacs écrivit : > the following is a code segment that opens a window and if 'q' is > pressed on the keyboard it closes it. It works with the byte code > compiler fine but does not react to pressed keys when compiled with the > native code compiler (using ocaml 3.04 for debian - from the unstable > distribution). > if mouse_action != (fun () -> ()) > then (if (try button_down()... > if key_pressed() ... > done;; I don't know the reason for those different behaviors, but you shoudn't wait for events this way because you actually burn CPU cycles for nothing until something happens. The following code works the same way with ocamlc and ocamlopt : open Graphics;; let map_keyboard = fun ?(mouse_action = (fun () -> ())) charactionlist -> let st = ref true in while !st do match wait_next_event [Button_down; Key_pressed] with | {button = true} -> mouse_action() | {keypressed = true; key=a} -> (try List.assoc a charactionlist () with Not_found -> ()); if a = 'q' then st := false | _ -> () done;; open_graph "";; map_keyboard [ ' ' , (fun () -> print_string "\n yes, it works!!"; flush stdout)];; close_graph();; Regards, -- Michel Quercia 57 rue abbé Grégoire, 38000 Grenoble http://michel.quercia.free.fr (maths) http://pauillac.inria.fr/~quercia (informatique) mailto:michel.quercia@prepas.org ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners