* three different labltk behaviors
@ 2007-08-04 23:56 Jeff Shaw
2007-08-05 2:28 ` [Caml-list] " Eric Cooper
2007-08-05 10:28 ` Jacques Garrigue
0 siblings, 2 replies; 3+ messages in thread
From: Jeff Shaw @ 2007-08-04 23:56 UTC (permalink / raw)
To: caml-list
Ocaml community,
For fun I wrote a version of Life for ocaml +labltk.
http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life
Here are the 3 ways I've tried to run it and the results:
1. compile to bytecode or native:
"Fatal error: exception Protocol.TkError("Tcl/Tk not initialised")"
2. #load all the libraries into the toplevel (or give them as command
line arguments) then #use "lifemain.ml":
works
3. Run the toplevel with "lifemain.ml" as an argument:
gives an empty Tk window
The results are the same on Mac OS X and Windows XP (mingw).
Here's the toplevel command:
ocaml -I +labltk -I +threads unix.cma labltk.cma threads.cma
tkthread.cmo life.cma lifeui.cma lifemain.ml
or leave off "lifemain.ml" and do a #use "lifemain.ml".
to compile:
ocamlc -I +labltk -I +threads -o life unix.cma labltk.cma threads.cma
tkthread.cmo life.cma lifeui.cma lifemain.ml
The sources are at
http://www.msu.edu/~shawjef3/life/life.ml
http://www.msu.edu/~shawjef3/life/lifeui.ml
http://www.msu.edu/~shawjef3/life/lifemain.ml
Any ideas about how to get a bytecode or native compiled version working?
Thanks,
Jeff
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] three different labltk behaviors
2007-08-04 23:56 three different labltk behaviors Jeff Shaw
@ 2007-08-05 2:28 ` Eric Cooper
2007-08-05 10:28 ` Jacques Garrigue
1 sibling, 0 replies; 3+ messages in thread
From: Eric Cooper @ 2007-08-05 2:28 UTC (permalink / raw)
To: caml-list
On Sat, Aug 04, 2007 at 07:56:42PM -0400, Jeff Shaw wrote:
> 1. compile to bytecode or native:
> "Fatal error: exception Protocol.TkError("Tcl/Tk not initialised")"
Make sure you have this:
let top = openTk ()
before any other Tk calls.
--
Eric Cooper e c c @ c m u . e d u
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] three different labltk behaviors
2007-08-04 23:56 three different labltk behaviors Jeff Shaw
2007-08-05 2:28 ` [Caml-list] " Eric Cooper
@ 2007-08-05 10:28 ` Jacques Garrigue
1 sibling, 0 replies; 3+ messages in thread
From: Jacques Garrigue @ 2007-08-05 10:28 UTC (permalink / raw)
To: shawjef3; +Cc: caml-list
From: Jeff Shaw <shawjef3@msu.edu>
> Ocaml community,
> For fun I wrote a version of Life for ocaml +labltk.
>
> http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life
>
> Here are the 3 ways I've tried to run it and the results:
>
> 1. compile to bytecode or native:
> "Fatal error: exception Protocol.TkError("Tcl/Tk not initialised")"
>
> 2. #load all the libraries into the toplevel (or give them as command
> line arguments) then #use "lifemain.ml":
> works
>
> 3. Run the toplevel with "lifemain.ml" as an argument:
> gives an empty Tk window
>
> The results are the same on Mac OS X and Windows XP (mingw).
There are two problems:
1) There is a buglet in Tkthread, which was originally intended to be
used only with the toplevel. Namely, the Tkthread.sync command executes
immediately in the current thread if there is no tk thread
running. This is to avoid deadlocks, but the new tk thread
registers itself, so there is a race condition if sync is called
immediately after Thread.start. For the time being, this can be
fixed by inserting
Thread.delay 0.001
2) You must "join" the tk thread before exiting, otherwise you will
exit immediately.
So you should correct the beginning of lifemain.ml with
open Tkthread
let tkth = start ()
let () = Thread.delay 0.001
and at the end of lifemain.ml
let () = Thread.join tkth
With this it works at least under unix.
Hope it helps.
Jacques Garrigue
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-08-05 10:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-04 23:56 three different labltk behaviors Jeff Shaw
2007-08-05 2:28 ` [Caml-list] " Eric Cooper
2007-08-05 10:28 ` Jacques Garrigue
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox