load sym-context problem

Notices and updates
Locked
Tim Johnson
Posts: 253
Joined: Thu Oct 07, 2004 7:21 pm
Location: Palmer Alaska USA

load sym-context problem

Post 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

rickyboy
Posts: 607
Joined: Fri Apr 08, 2005 7:13 pm
Location: Front Royal, Virginia

Post 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).
(λx. x x) (λx. x x)

Tim Johnson
Posts: 253
Joined: Thu Oct 07, 2004 7:21 pm
Location: Palmer Alaska USA

Post 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

Locked