caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] lablgtk newbie question
@ 2003-04-22 10:55 Richard Jones
  2003-04-22 11:42 ` Richard Jones
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Richard Jones @ 2003-04-22 10:55 UTC (permalink / raw)
  To: caml-list


Why do I have to run lablgtk programs using the 'lablgtk' interpreter?
What does this do above and beyond ordinary /usr/bin/ocaml?

It kind of reminds me (in a not very happy way) of the old problems
with Tcl/Tk where you needed to use a different version of 'wish' for
each extension you compiled in. Tell me this is not the same thing ...

Rich.

-- 
Richard Jones, Red Hat Inc. (London) and Merjis Ltd. http://www.merjis.com/
http://www.annexia.org/ Freshmeat projects: http://freshmeat.net/users/rwmj
PTHRLIB is a library for writing small, efficient and fast servers in C.
HTTP, CGI, DBI, lightweight threads: http://www.annexia.org/freeware/pthrlib/

-------------------
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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] lablgtk newbie question
  2003-04-22 10:55 [Caml-list] lablgtk newbie question Richard Jones
@ 2003-04-22 11:42 ` Richard Jones
  2003-04-22 13:01 ` Benjamin Monate
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Richard Jones @ 2003-04-22 11:42 UTC (permalink / raw)
  To: caml-list

More newbie questions ...

Below is my program so far.

It works, but it doesn't "look like" any of the example lablgtk
programs.  In particularly, I'm using a lot of ...

	let _ = ...

basically to execute an imperative statement. Perhaps this is a legacy
of the fact that I'm a very experienced imperative programmer.

I think I'm really confused about these:

let
let ... in
;
;;

Is there some good tutorial for this? My main reference is
http://caml.inria.fr/ocaml/htmlman/manual003.html but that doesn't
really explain these basics too well.

Comments & guidance welcome.

Rich.

open GMain
open GWindow
open GdkKeysyms

(* Top-level window *)
let window = GWindow.window ~width:500 ~height:300 ~title:"Editor" ()

let vbox = GPack.vbox ~packing:window#add ()

(* Menu bar *)
let menubar = GMenu.menu_bar ~packing:vbox#pack ()
let menubar_factory = new GMenu.factory menubar
let accel_group = menubar_factory#accel_group
let pages_menu = menubar_factory#add_submenu "Pages"
let edit_menu = menubar_factory#add_submenu "Edit"

(* Pages menu *)
let pages_factory = new GMenu.factory pages_menu ~accel_group
let _ = pages_factory#add_item "New blank page" ~key:_N
let _ = pages_factory#add_item "Search ..." ~key:_S

(* Edit menu *)
let edit_factory = new GMenu.factory edit_menu ~accel_group
let _ = edit_factory#add_item "Cut" ~key:_X
let _ = edit_factory#add_item "Copy" ~key:_C
let _ = edit_factory#add_item "Paste" ~key:_V

let main () =
  window#connect#destroy ~callback: Main.quit;
  window#show ();
  Main.main ();;

(* Run the main program *)
let _ = main ();;

-- 
Richard Jones, Red Hat Inc. (London) and Merjis Ltd. http://www.merjis.com/
http://www.annexia.org/ Freshmeat projects: http://freshmeat.net/users/rwmj
MONOLITH is an advanced framework for writing web applications in C, easier
than using Perl & Java, much faster and smaller, reusable widget-based arch,
database-backed, discussion, chat, calendaring:
http://www.annexia.org/freeware/monolith/

-------------------
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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] lablgtk newbie question
  2003-04-22 10:55 [Caml-list] lablgtk newbie question Richard Jones
  2003-04-22 11:42 ` Richard Jones
@ 2003-04-22 13:01 ` Benjamin Monate
  2003-04-22 13:08 ` Eric C. Cooper
  2003-04-22 13:12 ` Jacques Garrigue
  3 siblings, 0 replies; 6+ messages in thread
From: Benjamin Monate @ 2003-04-22 13:01 UTC (permalink / raw)
  To: Richard Jones; +Cc: caml-list

Richard Jones wrote:

>Why do I have to run lablgtk programs using the 'lablgtk' interpreter?
>What does this do above and beyond ordinary /usr/bin/ocaml?
>  
>

It a very simple convenience wrapper which selects a good precompiled 
toplevel with Gtk initialized.

You can get rid of it :
- for programs without threads, just start
     ocaml -I +lablgtk2 lablgtk.cma gtkInit.cmo

- with threads : 
    ocaml -I +threads -I +lablgtk2 unix.cma threads.cma lablgtk.cma 
gtkThread.cmo gtkInit.cmo gtkThInit.cmo


Replace lablgtk2 by lablgtk if you are a Gtk 1.* user.

>It kind of reminds me (in a not very happy way) of the old problems
>with Tcl/Tk where you needed to use a different version of 'wish' for
>each extension you compiled in. Tell me this is not the same thing ...
>  
>
This is not the same thing :-)
Moreover you may prefer to compile your programs instead of using an 
interactive toplevel.

Use  
ocamlc -I +lablgtk2 lablgtk.cma gtkInit.cmo myfile.ml

to produce portable bytecode or even

ocamlopt -I +lablgtk2 lablgtk.cmxa gtkInit.cmx myfile.ml
to produce native code.

Cheers
Benjamin


-------------------
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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] lablgtk newbie question
  2003-04-22 10:55 [Caml-list] lablgtk newbie question Richard Jones
  2003-04-22 11:42 ` Richard Jones
  2003-04-22 13:01 ` Benjamin Monate
@ 2003-04-22 13:08 ` Eric C. Cooper
  2003-04-22 13:12 ` Jacques Garrigue
  3 siblings, 0 replies; 6+ messages in thread
From: Eric C. Cooper @ 2003-04-22 13:08 UTC (permalink / raw)
  To: caml-list

On Tue, Apr 22, 2003 at 11:55:29AM +0100, Richard Jones wrote:
> Why do I have to run lablgtk programs using the 'lablgtk' interpreter?
> What does this do above and beyond ordinary /usr/bin/ocaml?

You don't; you can do the following instead:

$ ocaml -I +lablgtk lablgtk.cma
        Objective Caml version 3.06

# 

I think lablgtk is a hold-over from the days when the interpreter
didn't support the #load directive, so you had to build custom
top-levels with various libraries.

-- 
Eric C. Cooper          e c c @ c m u . e d u

-------------------
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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] lablgtk newbie question
  2003-04-22 10:55 [Caml-list] lablgtk newbie question Richard Jones
                   ` (2 preceding siblings ...)
  2003-04-22 13:08 ` Eric C. Cooper
@ 2003-04-22 13:12 ` Jacques Garrigue
  2003-04-22 13:28   ` Richard Jones
  3 siblings, 1 reply; 6+ messages in thread
From: Jacques Garrigue @ 2003-04-22 13:12 UTC (permalink / raw)
  To: rich; +Cc: caml-list

From: Richard Jones <rich@annexia.org>

> Why do I have to run lablgtk programs using the 'lablgtk' interpreter?
> What does this do above and beyond ordinary /usr/bin/ocaml?

Two years ago, when ocaml didn't have dynamic loading, this was a
requirement, like for old versions of Tcl as you say.

Nowadays, except on some exotic platform, this is just a question of
comfort: the toplevel is configured to make its use easier.
You can do the same thing by passing some options to the standard
toplevel:
        ocaml -w s -I +lablgtk lablgtk.cma gtkInit.cmo

Jacques Garrigue

-------------------
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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] lablgtk newbie question
  2003-04-22 13:12 ` Jacques Garrigue
@ 2003-04-22 13:28   ` Richard Jones
  0 siblings, 0 replies; 6+ messages in thread
From: Richard Jones @ 2003-04-22 13:28 UTC (permalink / raw)
  Cc: caml-list

Thanks everyone. I'm now using:

ocaml -w s -I +lablgtk lablgtk.cma gtkInit.cmo editor.ml

I notice that I can't put

#!/usr/bin/ocaml -w s -I +lablgtk lablgtk.cma gtkInit.cmo

at the beginning of my program. It complains of:

Couldnt get a file descriptor referring to the console
Could not get a file descriptor referring to the console
Couldnt get a file descriptor referring to the console
Could not get a file descriptor referring to the console
Couldnt get a file descriptor referring to the console
Could not get a file descriptor referring to the console
./editor.ml: line 8: let: =: syntax error: operand expected (error token is "=")
./editor.ml: line 9: syntax error near unexpected token `"Unimplemented: "'
./editor.ml: line 9: `  prerr_endline ("Unimplemented: " ^ msg);;'

Strange, but not a show-stopper.

I've also rewritten the program and worked out what the problem was
with ;; and ;. I'm assuming that ';' on its own is just a sequence
point, kind of like the monad stuff in Haskell (?)

And I'm using let ... in  as a short-hand for a local variable (except,
of course, I'm aware that it's not _really_ "variable").

My program looks like this now. Comments on style are welcome.

Rich.

open GMain
open GWindow
open GdkKeysyms

let unimplemented msg =
  prerr_endline ("Unimplemented: " ^ msg);;

let menu_new_blank_page () =
  unimplemented "New blank page function selected";;

let menu_search () =
  unimplemented "Search function selected";;

let menu_cut () =
  unimplemented "Cut function selected";;

let menu_copy () =
  unimplemented "Copy function selected";;

let menu_paste () =
  unimplemented "Paste function selected";;

let main () =
  (* Main window *)
  let window = GWindow.window ~width:500 ~height:300 ~title:"Editor" () in
  let vbox = GPack.vbox ~packing:window#add () in
  window#connect#destroy ~callback: Main.quit;

  (* Menu bar *)
  let menubar = GMenu.menu_bar ~packing:vbox#pack () in
  let factory = new GMenu.factory menubar in
  let accel_group = factory#accel_group in
  let pages_menu = factory#add_submenu "Pages" in
  let edit_menu = factory#add_submenu "Edit" in

  (* Pages menu *)
  let factory = new GMenu.factory pages_menu ~accel_group in
  factory#add_item "New blank page" ~key:_N ~callback: menu_new_blank_page;
  factory#add_item "Search ..." ~key:_S ~callback: menu_search;

  (* Edit menu *)
  let factory = new GMenu.factory edit_menu ~accel_group in
  factory#add_item "Cut" ~key:_X ~callback: menu_cut;
  factory#add_item "Copy" ~key:_C ~callback: menu_copy;
  factory#add_item "Paste" ~key:_V ~callback: menu_paste;

  (* Display the windows and enter Gtk+ main loop *)
  window#show ();
  Main.main ();;

(* Run the main program *)
main ();;


-- 
Richard Jones, Red Hat Inc. (London) and Merjis Ltd. http://www.merjis.com/
http://www.annexia.org/ Freshmeat projects: http://freshmeat.net/users/rwmj
MONOLITH is an advanced framework for writing web applications in C, easier
than using Perl & Java, much faster and smaller, reusable widget-based arch,
database-backed, discussion, chat, calendaring:
http://www.annexia.org/freeware/monolith/

-------------------
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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2003-04-22 13:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-22 10:55 [Caml-list] lablgtk newbie question Richard Jones
2003-04-22 11:42 ` Richard Jones
2003-04-22 13:01 ` Benjamin Monate
2003-04-22 13:08 ` Eric C. Cooper
2003-04-22 13:12 ` Jacques Garrigue
2003-04-22 13:28   ` Richard Jones

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).