Version française
Home     About     Download     Resources     Contact us    
Browse thread
confusion about mutable strings
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Ralph Douglass <ralph@g...>
Subject: confusion about mutable strings
I'm a little confused by some behavior I'm seeing.  Here is an example from
the toplevel:

# let foo () =
  let str = "ffff" in
  Printf.printf "%s\n%!" str;
  str.[0] <- 'r';
  str.[1] <- 'r';
  str.[2] <- 'r';
  str.[3] <- 'r';
  str
  ;;
val foo : unit -> string = <fun>
# foo ();;
ffff
- : string = "rrrr"
# foo ();;
rrrr
- : string = "rrrr"
#

Why isn't the output for the second printf also "ffff"?  It seems like it's
completely ignoring "let str =" the second time.

Any thoughts?  Is this a bug, or something I just don't know about?

3.10.1 on intel osx 10.5.1, installed from godi.

Thanks,
Ralph