History variables: Difference between revisions
Content added Content deleted
Line 986: | Line 986: | ||
=={{header|OCaml}}== |
=={{header|OCaml}}== |
||
The easiest solution is to use the Stack module coming with OCaml's standard library: |
|||
<lang ocaml> |
<lang ocaml> |
||
⚫ | |||
⚫ | |||
(* This is only for convenience when typing code *) |
|||
struct |
|||
⚫ | |||
let show_entry e = |
|||
type hist = { mutable hve: int list } |
|||
⚫ | |||
let init () = { hve = [] } |
|||
let push h e = |
|||
h.hve <- e::h.hve |
|||
let pop h = |
|||
match h.hve with |
|||
| [] -> () |
|||
| v::t -> h.hve <- t; print_int v; print_newline () |
|||
let show hv = |
|||
⚫ | |||
end |
|||
⚫ | |||
module H = History |
|||
let () = |
let () = |
||
let |
let hs = H.create() in |
||
H.push |
H.push 111 hs ; |
||
H.push |
H.push 4 hs ; |
||
H.push |
H.push 42 hs ; |
||
H. |
H.iter show_entry hs; |
||
H.pop |
hs |> H.pop |> Printf.printf "%d\n"; |
||
H.pop |
hs |> H.pop |> Printf.printf "%d\n"; |
||
H.pop |
hs |> H.pop |> Printf.printf "%d\n" |
||
</lang> |
</lang> |
||