Bruce Korb <bk...@gnu.org> writes: > On 01/06/12 10:13, Mark H Weaver wrote: >> Imagine that you were evaluating Scheme by hand on paper. You have your >> program written on one page, and you have another scratch page used for >> the data structures that your program creates during evaluation. >> Suppose your program contains a very large lookup table, written as a >> literal list. This lookup table is on your program page. >> >> Now, suppose.... > > That is where my mental model diverges!!
The mental model of the computer is what counts. >> sprintf(buf, "(define %s \"%s\")", "foo", my_str); >> scm_eval_string(buf); >> sprintf(buf, "(string-upcase! %s)", "foo") >> // the string from my_str in "buf" is now scribbled over and completely gone >> scm_eval_string(buf); > > Since I know the program I initially wrote (the define) is now gone, Why would a define be gone? > the string must have been copied off somewhere. I don't think you understand the concept of garbage collection. _Everything_ in Scheme exists permanently regarding all observable semantics (well, weak hash tables are a somewhat weird exception). Definitions, variables, continuations. There is no concept like a stack of local values that would get erased. Thanks to call/cc, there is not even a return stack that would get erased. Every object carries its own lifetime with it. It dies when nobody remembers it, not because of being in some scope or whatever else. > I think one's first guess is that it was copied to someplace > modifiable. However, that would be incorrect. It is copied off to > writable memory, but marked as read-only for the purposes of Guile. > Not intuitively obvious. Also wrong. -- David Kastrup