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

Just another of these basic things ...

Expand Messages
  • Michael Erdmann
    Hallo, there is another of these issues i need to get used to: Works : # List.length(x);; - : int = 1 # so i expected the following to work; but i got: #
    Message 1 of 8 , May 8, 2012
    • 0 Attachment
      Hallo,

      there is another of these issues i need to get used to:

      Works :
      # List.length(x);;
      - : int = 1
      #

      so i expected the following to work; but i got:

      # print_int List.length(x);;
      print_int List.length(x);;
      Error: This function is applied to too many arguments;
      maybe you forgot a `;'

      what finally works

      # List.length(x);;
      - : int = 1
      # print_int (List.length x);;
      1- : unit = ()
      #

      seems that print_int List.length(x) is read by like

      print_int List.length (x)

      meaning print_int gets two arguments; correct?

      Woudn't it be better in the first case to issue an warning that there
      should
      be at least a blank like List.length (x).

      This seems to be completely different in comparison to other languages
      like
      Ada; Java and requires some time to get used to it :-)))



      /Michael
    • Francois Berenger
      ... If you use batteries, you can write: List.length x | print_int If you don t have batteries, you can define: let (| ) x f = f x;; Personally, I m not a fan
      Message 2 of 8 , May 8, 2012
      • 0 Attachment
        On 05/09/2012 02:07 PM, Michael Erdmann wrote:
        > Hallo,
        >
        > there is another of these issues i need to get used to:
        >
        > Works :
        > # List.length(x);;
        > - : int = 1
        > #
        >
        > so i expected the following to work; but i got:
        >
        > # print_int List.length(x);;
        > print_int List.length(x);;
        > Error: This function is applied to too many arguments;
        > maybe you forgot a `;'
        >
        > what finally works
        >
        > # List.length(x);;
        > - : int = 1
        > # print_int (List.length x);;
        > 1- : unit = ()

        If you use batteries, you can write:

        List.length x |> print_int

        If you don't have batteries, you can define:
        let (|>) x f = f x;;

        Personally, I'm not a fan of this notation but some are.

        > seems that print_int List.length(x) is read by like
        >
        > print_int List.length (x)
        >
        > meaning print_int gets two arguments; correct?
        >
        > Woudn't it be better in the first case to issue an warning that there
        > should
        > be at least a blank like List.length (x).
        >
        > This seems to be completely different in comparison to other languages
        > like
        > Ada; Java and requires some time to get used to it :-)))
        >
        > /Michael
        >
        >
      • Gabriel Scherer
        I have a (slowly moving) project of FAQ for beginners where I explain things that, in my experience, beginners have a hard time understanding about OCaml.
        Message 3 of 8 , May 8, 2012
        • 0 Attachment
          I have a (slowly moving) project of "FAQ for beginners" where I
          explain things that, in my experience, beginners have a hard time
          understanding about OCaml. Perhaps surprisingly, parethenses is one of
          those things -- OCaml rules are extremely simple and consistent, but
          that's one domain where familiarity trumps simplicity.

          Michael, do not hesitate to have a look. Any feedback would be warmly welcome.
          http://yquem.inria.fr/~protzenk/caml-faq/doku.php?id=parentheses

          (There is already an official FAQ for OCaml, whose answers are very
          good but cover a more restricted range of subjects, and I think has
          value for the more advanced questions. Do not hesitate to have a look
          as well, though it won't answer this specific question.
          http://caml.inria.fr/resources/doc/faq/index.en.html
          )

          On Wed, May 9, 2012 at 8:32 AM, Christophe TROESTLER
          <Christophe.Troestler@...> wrote:
          > Hi,
          >
          > On Wed, 9 May 2012 07:07:38 +0200, Michael Erdmann wrote:
          >>
          >> seems that print_int List.length(x) is read by like
          >>
          >> print_int List.length (x)
          >>
          >> meaning print_int gets two arguments; correct?
          >
          > Yes.
          >
          >> Woudn't it be better in the first case to issue an warning that
          >> there should be at least a blank like List.length (x).
          >
          > Adding spaces will not change anything.
          >
          >> This seems to be completely different in comparison to other
          >> languages like Ada; Java and requires some time to get used to
          >> it :-)))
          >
          > Right but the syntax is also slightly different -- no use of the tuple
          > notations for arguments. This is motivated by partial evaluation.
          >
          > Hope it helps,
          > C.
          >
          >
          > ------------------------------------
          >
          > Archives up to December 31, 2011 are also downloadable at http://www.connettivo.net/cntprojects/ocaml_beginners
          > The archives of the very official ocaml list (the seniors' one) can be found at http://caml.inria.fr
          > Attachments are banned and you're asked to be polite, avoid flames etc.Yahoo! Groups Links
          >
          >
          >
        • Markus Weißmann
          Hi, I d guess that your underlying misunderstanding is, that -- unlike in C & Java -- function calls don t use parenthesis: # List.length(x) is really just the
          Message 4 of 8 , May 9, 2012
          • 0 Attachment
            Hi,

            I'd guess that your underlying misunderstanding is, that -- unlike in C
            & Java -- function calls don't use parenthesis:

            # List.length(x)

            is really just the same as

            # List.length x

            as the following two statements do the same in C & Java:

            int i = foo(5);
            int i = foo((5));



            Regards

            -Markus


            On 2012-05-09 07:07, Michael Erdmann wrote:
            >
            > there is another of these issues i need to get used to:
            >
            > Works :
            > # List.length(x);;
            > - : int = 1
            > #
            >
            > so i expected the following to work; but i got:
            >
            > # print_int List.length(x);;
            > print_int List.length(x);;
            > Error: This function is applied to too many arguments;
            > maybe you forgot a `;'
            >
            > what finally works
            >
            > # List.length(x);;
            > - : int = 1
            > # print_int (List.length x);;
            > 1- : unit = ()
            > #
            >
            > seems that print_int List.length(x) is read by like
            >
            > print_int List.length (x)
            >
            > meaning print_int gets two arguments; correct?
            >
            > Woudn't it be better in the first case to issue an warning that there
            > should
            > be at least a blank like List.length (x).
            >
            > This seems to be completely different in comparison to other
            > languages
            > like
            > Ada; Java and requires some time to get used to it :-)))
            >
            >
            >
            > /Michael

            --
            Markus Weißmann, M.Sc.
            Technische Universität München
            Institut für Informatik
            Boltzmannstr. 3
            D-85748 Garching
            Germany
            http://wwwknoll.in.tum.de/
          • spir
            ... Then do not hesitate covering in depth all questions of (non) delimitation of all kinds in OCaml. Especially about ; ; . I still did not get that right.
            Message 5 of 8 , May 9, 2012
            • 0 Attachment
              On 05/09/2012 08:59 AM, Gabriel Scherer wrote:
              > I have a (slowly moving) project of "FAQ for beginners" where I
              > explain things that, in my experience, beginners have a hard time
              > understanding about OCaml. Perhaps surprisingly, parethenses is one of
              > those things -- OCaml rules are extremely simple and consistent, but
              > that's one domain where familiarity trumps simplicity.
              >
              > Michael, do not hesitate to have a look. Any feedback would be warmly welcome.
              > http://yquem.inria.fr/~protzenk/caml-faq/doku.php?id=parentheses

              Then do not hesitate covering in depth all questions of (non) delimitation of
              all kinds in OCaml. Especially about ';' ';'. I still did not get that right. I
              think originally designers tried to avoid syntactic noise as much as possible,
              which is great indeed, but for any reason, in Ocaml only, this makes syntax
              rules about delimitation (of logically related things in blocks of code, and of
              little block in higher blocks) about non-graspable for /many/. And for still
              another reason I don't get right, bracing simply does not help (the case of the
              op is not one I evoke here, it is just a normal problem of lang syntax/semantics).

              Denis
            • Michael Erdmann
              ... May be part of my missunderstanding comes from the ocaml reference manual. In the introduction you will find: ... # square(sin pi) +. square(cos pi);; ...
              Message 6 of 8 , May 9, 2012
              • 0 Attachment
                On 05/09/2012 10:02 AM, Markus Weißmann wrote:
                >
                >
                > Hi,
                >
                > I'd guess that your underlying misunderstanding is, that -- unlike in C
                > & Java -- function calls don't use parenthesis:
                >
                May be part of my missunderstanding comes from the ocaml reference
                manual. In the
                introduction you will find:
                ...

                # square(sin pi) +. square(cos pi);;

                :-))

                >
                > # List.length(x)
                >
                > is really just the same as
                >
                > # List.length x
                >
                > as the following two statements do the same in C & Java:
                >
                > int i = foo(5);
                > int i = foo((5));
                >
                > Regards
                >
                > -Markus
                >
                > On 2012-05-09 07:07, Michael Erdmann wrote:
                > >
                > > there is another of these issues i need to get used to:
                > >
                > > Works :
                > > # List.length(x);;
                > > - : int = 1
                > > #
                > >
                > > so i expected the following to work; but i got:
                > >Pantyhose sex girl in shiny hose fuck ! - xHamster.com
                > > # print_int List.length(x);;
                > > print_int List.length(x);;
                > > Error: This function is applied to too many arguments;
                > > maybe you forgot a `;'
                > >
                > > what finally works
                > >
                > > # List.length(x);;
                > > - : int = 1
                > > # print_int (List.length x);;
                > > 1- : unit = ()
                > > #
                > >
                > > seems that print_int List.length(x) is read by like
                > >
                > > print_int List.length (x)
                > >
                > > meaning print_int gets two arguments; correct?
                > >
                > > Woudn't it be better in the first case to issue an warning that there
                > > should
                > > be at least a blank like List.length (x).
                > >
                > > This seems to be completely different in comparison to other
                > > languages
                > > like
                > > Ada; Java and requires some time to get used to it :-)))
                > >
                > >
                > >
                > > /Michael
                >
                > --
                > Markus Weißmann, M.Sc.
                > Technische Universität München
                > Institut für Informatik
                > Boltzmannstr. 3
                > D-85748 Garching
                > Germany
                > http://wwwknoll.in.tum.de/
                >
                >



                [Non-text portions of this message have been removed]
              • danbensen@att.net
                ... The parentheses are required because function application is left associative. There s a precedence and associativity table here:
                Message 7 of 8 , May 9, 2012
                • 0 Attachment
                  > > I'd guess that your underlying misunderstanding is, that
                  > > -- unlike in C & Java -- function calls don't use parenthesis

                  > May be part of my missunderstanding comes from
                  > the ocaml reference manual.
                  > # square(sin pi) +. square(cos pi);;

                  The parentheses are required because function application is
                  left associative. There's a precedence and associativity table
                  here:
                  http://caml.inria.fr/pub/docs/manual-ocaml/expr.html

                  > > > Woudn't it be better in the first case to issue an warning
                  > > > that there should be at least a blank like List.length (x).

                  You don't need whitespace as long as the argument lexes to a separate token. Blanks and newlines are deleted from the token stream before parsing, so they don't do anything except separate items for lexing.
                • Gabriel Scherer
                  ... I have submitted a bugreport to change this in the manual. http://caml.inria.fr/mantis/view.php?id=5612 I will probably try to propose a patch for it
                  Message 8 of 8 , May 10, 2012
                  • 0 Attachment
                    > May be part of my missunderstanding comes from the ocaml reference
                    > manual. In the
                    > introduction you will find:
                    > ...
                    >
                    > # square(sin pi) +. square(cos pi);;
                    >
                    > :-))

                    I have submitted a bugreport to change this in the manual.
                    http://caml.inria.fr/mantis/view.php?id=5612

                    I will probably try to propose a patch for it myself, once I have some
                    free time to learn how to compile the manual from the SVN repository.
                    Of course, if someone wants to do it, I'd be delighted.

                    On Wed, May 9, 2012 at 9:02 PM, Michael Erdmann
                    <erdmann-berlin@...> wrote:
                    > On 05/09/2012 10:02 AM, Markus Weißmann wrote:
                    >>
                    >>
                    >> Hi,
                    >>
                    >> I'd guess that your underlying misunderstanding is, that -- unlike in C
                    >> & Java -- function calls don't use parenthesis:
                    >>
                    > May be part of my missunderstanding comes from the ocaml reference
                    > manual. In the
                    > introduction you will find:
                    > ...
                    >
                    > # square(sin pi) +. square(cos pi);;
                    >
                    > :-))
                    >
                    >>
                    >> # List.length(x)
                    >>
                    >> is really just the same as
                    >>
                    >> # List.length x
                    >>
                    >> as the following two statements do the same in C & Java:
                    >>
                    >> int i = foo(5);
                    >> int i = foo((5));
                    >>
                    >> Regards
                    >>
                    >> -Markus
                    >>
                    >> On 2012-05-09 07:07, Michael Erdmann wrote:
                    >> >
                    >> > there is another of these issues i need to get used to:
                    >> >
                    >> > Works :
                    >> > # List.length(x);;
                    >> > - : int = 1
                    >> > #
                    >> >
                    >> > so i expected the following to work; but i got:
                    >> >Pantyhose sex girl in shiny hose fuck ! - xHamster.com
                    >> > # print_int List.length(x);;
                    >> > print_int List.length(x);;
                    >> > Error: This function is applied to too many arguments;
                    >> > maybe you forgot a `;'
                    >> >
                    >> > what finally works
                    >> >
                    >> > # List.length(x);;
                    >> > - : int = 1
                    >> > # print_int (List.length x);;
                    >> > 1- : unit = ()
                    >> > #
                    >> >
                    >> > seems that print_int List.length(x) is read by like
                    >> >
                    >> > print_int List.length (x)
                    >> >
                    >> > meaning print_int gets two arguments; correct?
                    >> >
                    >> > Woudn't it be better in the first case to issue an warning that there
                    >> > should
                    >> > be at least a blank like List.length (x).
                    >> >
                    >> > This seems to be completely different in comparison to other
                    >> > languages
                    >> > like
                    >> > Ada; Java and requires some time to get used to it :-)))
                    >> >
                    >> >
                    >> >
                    >> > /Michael
                    >>
                    >> --
                    >> Markus Weißmann, M.Sc.
                    >> Technische Universität München
                    >> Institut für Informatik
                    >> Boltzmannstr. 3
                    >> D-85748 Garching
                    >> Germany
                    >> http://wwwknoll.in.tum.de/
                    >>
                    >>
                    >
                    >
                    >
                    > [Non-text portions of this message have been removed]
                    >
                    >
                    >
                    > ------------------------------------
                    >
                    > Archives up to December 31, 2011 are also downloadable at http://www.connettivo.net/cntprojects/ocaml_beginners
                    > The archives of the very official ocaml list (the seniors' one) can be found at http://caml.inria.fr
                    > Attachments are banned and you're asked to be polite, avoid flames etc.Yahoo! Groups Links
                    >
                    >
                    >
                  Your message has been successfully submitted and would be delivered to recipients shortly.