Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

`let` defines a value. Some values are "plain old values", some are functions.

The syntax is `let <constantname> <parameters> = <value> in <expression>;;` where `expression` can also have `let` bindings.

So you can have

  let one = 1 in
  let two = 2 in
  let three = one + two in
  print_endline (string_of_int three);;


The way I always think about it is in terms of scope. With:

  let x = v in expr
`x` is now available for use in `expr`

In essence, an OCaml program is a giant recursive expression, because `expr` can have its own set of let definitions.

In the REPL, this is where the double semicolons come in, as a sort of hint to continue processing after the expression.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: