Re: References and constant pointers
- From: "K" <carlosayam@xxxxxxxxxxxx>
- Date: Thu, 14 Sep 2006 22:43:11 +0000 (UTC)
Hi
I would translate 'val x = ref 0'; as 'int x = 0', as 'x' is simply a
'int * const' in C by itself. This simply reflects that in ML stateful
computation is explicitly defined, whereas in C is implicit (everything
is carrying state)... and, besides, C programs derived from ML don't
have to be that complicated ;-)
cheers
Carlos Aya
p.s. let recommend you this http://www.info.ucl.ac.be/~pvr/book.html
for further reading about stateless/stateful programming paradigms.
cane wrote:
Hi, I'm trying to better understand the concept of reference in SML.
For what I've been able to grasp till now, and trying to draw an
analogy, a reference variable is much like a constant pointer in C, e.g.:
this SML snippet:
val x = ref 0;
Could be translated in C to something like:
int val = 0;
int* const x = &val;
Basically, you can modify the value of the pointed variable, but you
can't modify which variable the pointer points to.
So, standing the definitions above, you can do (SML): x := 1; as you can
do (C): *x = 1; but you cannot do (SML): val x = ref 1; (new binding for
the same identifier) as you cannot do (C): x = &val2; is that correct?
Thanks, bye.
.
- References:
- References and constant pointers
- From: cane
- References and constant pointers
- Prev by Date: Re: References and constant pointers
- Next by Date: FSEN'07 Second call for papers (International Symposium on Fundamentals of Software Engineering)
- Previous by thread: Re: References and constant pointers
- Next by thread: Re: Alice 1.3 released
- Index(es):
Relevant Pages
|