From 54fbe594d89513d332a82e414fc814d5e2de8815 Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Wed, 19 Sep 2018 11:06:37 -0400 Subject: [PATCH] Hide counter inside closure --- compiler/src/lib/tiger/tiger_symbol.ml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/compiler/src/lib/tiger/tiger_symbol.ml b/compiler/src/lib/tiger/tiger_symbol.ml index 747cb03..a850406 100644 --- a/compiler/src/lib/tiger/tiger_symbol.ml +++ b/compiler/src/lib/tiger/tiger_symbol.ml @@ -5,14 +5,16 @@ type t = ; symbol : int } -let counter = ref 0 +let next = + let counter = ref 0 in + fun () -> + incr counter; + !counter let symbols = H.create 16 let unique_of_string name = - incr counter; - let symbol = !counter in - {name; symbol} + {name; symbol = next ()} let of_string name = match H.find_opt symbols name with -- 2.20.1