Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] OCaml wishlist
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques Garrigue <garrigue@k...>
Subject: Re: [Caml-list] OCaml wishlist
From: Richard Jones <rich@annexia.org>

> I'm really looking for help on this! My working theory at the moment
> though is that writing UIs involves writing essentially imperative
> code. One small example from some real code:
> 
>   let quit _ =
>     if !test_id = 0 then (
>       GMain.Main.quit (); false
>     ) else (
>       let icon = GMisc.image () in
>       icon#set_stock `DIALOG_QUESTION;
>       icon#set_icon_size `DIALOG;
>       let buttons = [ "Quit"; "Cancel" ] in
>       let ans = GToolbox.question_box ~title:"Quit" ~icon ~buttons
>           ("Are you sure you want to quit? This may lose any\n" ^
>            "results from this assessment.") in
>       if ans = 1 then (
>         GMain.Main.quit (); false       (* User requested quit. *)
>        )
>       else
>         true                            (* Don't close the window. *)
>      )

This is only a problem of indentation:

  let quit _ =
    if !test_id = 0 then (GMain.Main.quit (); false) else
    let icon = GMisc.image () in
    icon#set_stock `DIALOG_QUESTION;
    icon#set_icon_size `DIALOG;
    let buttons = [ "Quit"; "Cancel" ] in
    let ans = GToolbox.question_box ~title:"Quit" ~icon ~buttons
        ("Are you sure you want to quit? This may lose any\n" ^
         "results from this assessment.") in
    ans <> 1 || (GMain.Main.quit (); false)

Of course you have to be careful: you can shoot yourself in the foot
with wrong indentation:

  let quit _ =
    let icon = GMisc.image () in
    if !test_id = 0 then (GMain.Main.quit (); false) else
    icon#set_stock `DIALOG_QUESTION;
    icon#set_icon_size `DIALOG;
    [...]

In this case you're just going to jump over icon#set_stock...

Jacques

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