Phani Raj
Phani Raj

Reputation: 173

How to create variables dynamically in OCaml?

I am new to OCaml. I want to create new variables dynamically in a loop.

I tried few like x.(i), x.i, and tried to create names using fprintf.

Upvotes: 1

Views: 198

Answers (1)

gsg
gsg

Reputation: 9377

You can't: OCaml is a static language in which the number, scope and name of variables is fixed. If you want a way to dynamically map strings to values, use a hashtable or map.

Upvotes: 2

Related Questions