Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Ml > Re: Destructive...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 5 Topic 868 of 973
Post > Topic >>

Re: Destructive Assignment in SML

by "Albert Y. C. Lai" <trebla@[EMAIL PROTECTED] > Apr 19, 2007 at 10:25 PM

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
 




 5 Posts in Topic:
Destructive Assignment in SML
Rob Hoelz <hoelz@[EMAI  2007-04-17 21:42:58 
Re: Destructive Assignment in SML
torbenm@[EMAIL PROTECTED]  2007-04-19 22:24:34 
Re: Destructive Assignment in SML
"Albert Y. C. Lai&qu  2007-04-19 22:25:05 
Re: Destructive Assignment in SML
dbenson@[EMAIL PROTECTED]  2007-04-19 22:25:15 
Re: Destructive Assignment in SML
Vesa Karvonen <vesa.ka  2007-04-19 22:25:40 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Nov 21 23:48:13 CST 2008.