Commit 4fabb29f authored by POTTIER Francois's avatar POTTIER Francois

New abstract type [Gensym.generator].

parent 4983dafc
# CHANGES
## 2019/XX/XX
* In `Gensym`, new abstract type `generator`,
with three functions `generator`, `fresh`, and `current`.
## 2018/11/30
* New release, including new modules (`Gensym`, `Memoize`,
......
......@@ -23,3 +23,17 @@ let make () =
(* We do not worry about overflow. On today's 64-bit machines, it won't occur
in a lifetime. *)
type generator =
int ref
let generator () =
ref 0
let fresh c =
let y = !c in
c := y + 1;
y
let current c =
!c
......@@ -18,3 +18,17 @@ type gensym =
(* [make()] produces a new gensym. *)
val make : unit -> gensym
(* A slightly more powerful abstraction is a generator whose current state
can be inspected (without modification). *)
type generator
(* [generator()] creates a new generator. [fresh generator] causes the
generator to create and return a fresh integer identifier. [current
generator] returns the generator's current state, that is, the next
available integer identifier. *)
val generator: unit -> generator
val fresh: generator -> int
val current: generator -> int
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment