Jump to content

  •  

Photo

Creating Variables

Code Snippet

  • Please log in to reply
No replies to this topic

#1 Wilson18

Wilson18

    Administrator

  • root
  • 112 posts
  • LocationUniversity of Birmingham

Posted 02 November 2014 - 06:21 PM

Below you can see some examples for how to create some examples in OCaml. Try and figure out the outputs yourself but if you get stuck, check the screenshots!

(* Creating a variable *)
let v = 1;;

(* Adding two variables together *)
v+v;;

(* Variables within Variables - Inception.*)
let v = 2 in v + v;;

(* The above code does not change the value of v*)
v + v;;

(* More complicated examples of above *)
let v = 1 in (let v = 5 in v * v) - (v * v);;

Attached File  Screen Shot 2014-11-02 at 18.18.43.png   32.49KB   0 downloads

 


List what you read?

Check me out on: YouTube, Twitter, Facebook, Google+






Also tagged with one or more of these keywords: Code Snippet