Page 1 of 1

load sym-context problem

Posted: Sat May 17, 2008 10:53 pm
by Tim Johnson
I have a file created by 'save. session.lsp

Code: Select all

(context 'g)
(set 'action "Viewing file: testcgi.dbg")
(set 'home "/home/http/run/newlisp")
(set 'log-ex '(".dbg" ".err" ".ok"))
(set 'target-file "testcgi.dbg")
(set 'top-dir "/home/http/run/")
(context 'MAIN)
When I attempt to load this file without the option sym-context parameter,
all is good:

Code: Select all

> (load "session.lsp")
MAIN
> g:top-dir
"/home/http/run/"
When I load with 'sym-context I expected the symbol to contain
all members and values as the original but the following is not what I expected.

Code: Select all

> (load "session.lsp" 'gg)
MAIN
> gg:top-dir
nil
> (symbols 'gg)
(gg:g gg:top-dir)
I guess I need some clarification.
FYI: What I want to be able to do is
save variables from a session, reload them at
the next execution of the script without overwriting the
current variables.
Thanks
Tim

Posted: Sun May 18, 2008 1:01 am
by rickyboy
If your session.lsp just looked like this:

Code: Select all

(set 'action "Viewing file: testcgi.dbg")
(set 'home "/home/http/run/newlisp")
(set 'log-ex '(".dbg" ".err" ".ok"))
(set 'target-file "testcgi.dbg")
(set 'top-dir "/home/http/run/")
i.e. no context expressions, then evaluating this in newlisp:

Code: Select all

(load "session.lsp" 'gg)
would give you what you need.

In the original case, load still has to respect the context expressions. And since you loaded everything "under" the gg context, when the loader gets to (context 'g), it's gonna create the context "under" gg. That's why you're getting gg:g when you inspect the symbols. But the rest, go in the g context, and this makes sense, since you had noticed earlier that all contexts are under MAIN (i.e. no cascading contexts in newlisp).

Posted: Sun May 18, 2008 2:48 am
by Tim Johnson
Ah!
I think I misread the documentation.
I believe that the following should get me what I'm looking for:

Code: Select all

> (load "session.lsp")
MAIN
> (new g 'prv)
So now I have a copy of the previous session in 'prv
and subsequent writes to 'g would not change 'prv.

Thanks
Tim