Jump to content

History variables: Difference between revisions

→‎{{header|Oberon-2}}: Added OCaml version just below Oberon-2
(→‎{{header|Tcl}}: added zkl)
(→‎{{header|Oberon-2}}: Added OCaml version just below Oberon-2)
Line 983:
ShowVal(history.Undo());
END HVar.
</lang>
 
=={{header|OCaml}}==
<lang ocaml>
module History =
struct
 
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 =
List.iter (fun v -> Printf.printf "History entry: %5d\n" v) hv.hve
end
 
open History
module H = History
 
let () =
let hv = H.init() in
H.push hv 111;
H.push hv 4;
H.push hv 42;
H.show hv;
H.pop hv;
H.pop hv;
H.pop hv
</lang>
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.