caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Michel Quercia <michel.quercia@prepas.org>
To: Attila Kondacs <attila@zurich.ai.mit.edu>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] native-code and byte-code compiler differences
Date: Sun, 31 Mar 2002 20:59:37 +0200	[thread overview]
Message-ID: <20020331205937.295fa6f5.michel.quercia@prepas.org> (raw)
In-Reply-To: <Pine.LNX.4.21.0203291538590.19082-100000@neuchatel.ai.mit.edu>

Le Fri, 29 Mar 2002 16:00:41 -0500 (EST)
Attila Kondacs <attila@zurich.ai.mit.edu> é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


  reply	other threads:[~2002-04-01 21:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-03-29 21:00 Attila Kondacs
2002-03-31 18:59 ` Michel Quercia [this message]
2002-03-31 19:09 ` Sylvain LE GALL
2002-03-31 19:32 ` Tim Freeman
2002-04-02 17:14 ` Andrej Bauer

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=20020331205937.295fa6f5.michel.quercia@prepas.org \
    --to=michel.quercia@prepas.org \
    --cc=attila@zurich.ai.mit.edu \
    --cc=caml-list@inria.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;
as well as URLs for NNTP newsgroup(s).