The problem is not the way you update the reference, but that makeEtiClass
is not a function, just a variable holding a string, that happens to increment cptIdCO
once before initializing it.
A function differs from a variable in that it takes arguments. You can use unit, ()
, if it doesn't need anything else.
This will do what you expect:
let cptIdCO = ref 0;; (* compteur : id Classe et Object globale *)
let makeEtiClassOrObj () =
cptIdCO := !cptIdCO + 1;
"ClObj_" ^ (string_of_int !cptIdCO) ^ ": NOP
";;
let compileClass cls =
print_string "-- compileClass
";
(*fillClass cls;*)
print_string (makeEtiClassOrObj ())
and compileObject obj =
print_string "-- compileObject
";
print_string (makeEtiClassOrObj ())
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…