Rob Hoelz wrote:
> I won't lie; this is for a homework assignment,
I hope it is not a destructive assignment. XD
> val memory = []
[...]
> ((val memory = ((m, result) :: memory)); result)
> end
> end
>
> Unfortunately, (val memory = ...) doesn't accomplish what I need; it
> causes a syntax error. Could somone shed some light on how I could
> assign to memory? Thanks!
"val memory = []" creates memory to be immutable.
"val memory = ref []" creates memory to be a reference to a mutable
variable, and initializes the variable to []. While the reference itself
(a pointer) is immutable (clearly a good thing), what it points to is
mutable. To read the current value of the variable, use "!memory". To
change it, use "memory := newvalue". Example:
memory := (m, result) :: !memory


|