Content deleted Content added
Tags: Mobile edit Mobile web edit |
Add the OCaml programming language. |
||
Line 659:
Hello there
=> #<ExampleClass:0x007fb3f4299118>
</source>
=== OCaml ===
In [[OCaml (programming language)|OCaml]], there is one constructor. Parameters are defined right after the class name. They can be used to initialize instance variables and are accessible throughout the class. An anonymous hidden method called <code>initializer</code> allows to evaluate an expression immediately after the object has been built.
<ref>[http://caml.inria.fr/pub/docs/manual-ocaml/index.html]</ref>
<source lang="ocaml">
class person first_name last_name =
object
val full_name = first_name ^ " " ^ last_name
initializer
print_endline("Hello there, I am " ^ full_name ^ ".")
method get_last_name = last_name
end;;
let alonzo = new person "Alonzo" "Church" in (*Hello there, I am Alonzo Church.*)
print_endline alonzo#get_last_name (*Church*)
</source>
|