Loading ...
Sorry, an error occurred while loading the content.

Using the Arg module

Expand Messages
  • Johann Spies
    I am trying to understand how to use the Arg module. In the following code the string parameters work as I expected it, but not the switches:
    Message 1 of 3 , Feb 3, 2003
    • 0 Attachment
      I am trying to understand how to use the Arg module.

      In the following code the string parameters work as I expected it, but
      not the switches:

      ==================
      open Arg

      let v = ref false
      let ver = ref false
      let c = ref false
      let s = ref ""
      let d = ref ""


      let version = if !ver then
      begin
      print_string "Version 1.0";
      print_newline()
      end


      let verbose = if !v then
      begin
      print_string "verbose aangeskakel";
      print_newline()
      end

      let compare = if !c then
      begin
      print_string "lêervergelyking aangeskakel";
      print_newline()
      end


      let bestemming a= d:= a;
      Printf.printf "Bestemming: %s" !d;
      print_newline()

      let bron a = s:=a;
      Printf.printf "Bron: %s" !s;
      print_newline()


      let read_args() =
      let speclist = [("-V", Arg.Set ver, "Show version");
      ("-v", Arg.Set v, "Verbose");
      ("-c", Arg.Set c,
      "Compare files before deleting");
      ("-d", Arg.String (bestemming ), "Destination");
      ("-s", Arg.String (bron), "Source")]
      in let usage_msg =
      "usage : duprem [-vVc] -s <source> -d <destination>"
      in Arg.parse speclist (fun s -> ()) usage_msg

      let _ = read_args();
      verbose;
      version;
      compare
      ====================

      The following illustrates my problem:

      zsh % ./toets_args -c -V -v -d daar -s hier
      Bestemming: daar
      Bron: hier


      The switches -c, -V and -v are not set as I expected it to be.

      What am I missing?

      Johann
      --
      Johann Spies Telefoon: 021-808 4036
      Informasietegnologie, Universiteit van Stellenbosch

      "O come, let us worship and bow down; let us kneel
      before the LORD our maker." Psalms 95:6
    • Remi VANICAT
      ... this is not a function. It take no argument. This compute (immediately) if !ver then begin print_string Version 1.0 ; print_newline() end which value is
      Message 2 of 3 , Feb 3, 2003
      • 0 Attachment
        Johann Spies <jspies@...> writes:

        > I am trying to understand how to use the Arg module.
        >
        > In the following code the string parameters work as I expected it, but
        > not the switches:
        >
        > ==================
        > open Arg
        >
        > let v = ref false
        > let ver = ref false
        > let c = ref false
        > let s = ref ""
        > let d = ref ""
        >
        >
        > let version = if !ver then
        > begin
        > print_string "Version 1.0";
        > print_newline()
        > end

        this is not a function. It take no argument. This compute (immediately)
        if !ver then
        begin
        print_string "Version 1.0";
        print_newline()
        end

        which value is (), and bind version to the result.

        if you want a function, you should write


        let version () =
        if !ver then
        begin
        print_string "Version 1.0";
        print_newline()
        end

        [...]

        [...]


        --
        Rémi Vanicat
        vanicat@labri.u-bordeaux.fr
        http://dept-info.labri.u-bordeaux.fr/~vanicat
      • Johann Spies
        ... Thanks Remi. It seems that I am a slow learner. I have made this mistake before. Regards. Johann -- Johann Spies Telefoon: 021-808 4036
        Message 3 of 3 , Feb 3, 2003
        • 0 Attachment
          On Mon, Feb 03, 2003 at 02:27:49PM +0100, Remi VANICAT wrote:
          > Johann Spies <jspies@...> writes:
          >

          > > let version = if !ver then
          > > begin
          > > print_string "Version 1.0";
          > > print_newline()
          > > end
          >
          > this is not a function. It take no argument. This compute (immediately)
          > if !ver then
          > begin
          > print_string "Version 1.0";
          > print_newline()
          > end
          >
          > which value is (), and bind version to the result.
          >
          > if you want a function, you should write
          >
          >
          > let version () =
          > if !ver then
          > begin
          > print_string "Version 1.0";
          > print_newline()
          > end
          >

          Thanks Remi. It seems that I am a slow learner. I have made this
          mistake before.

          Regards.
          Johann

          --
          Johann Spies Telefoon: 021-808 4036
          Informasietegnologie, Universiteit van Stellenbosch

          "O come, let us worship and bow down; let us kneel
          before the LORD our maker." Psalms 95:6
        Your message has been successfully submitted and would be delivered to recipients shortly.