[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4762: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4764: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4765: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4766: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
newlispfanclub.alh.net • View topic - Load and Save of contexts using encrypt

Load and Save of contexts using encrypt

Q&A's, tips, howto's

Load and Save of contexts using encrypt

Postby CaveGuy » Mon Oct 21, 2002 9:05 pm

CaveGuy
 
Posts: 112
Joined: Sun Oct 13, 2002 3:00 pm
Location: Columbus Ohio

Postby Lutz » Tue Oct 22, 2002 12:02 am

Lutz
 
Posts: 5279
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California

Postby CaveGuy » Tue Oct 22, 2002 3:55 am

CaveGuy
 
Posts: 112
Joined: Sun Oct 13, 2002 3:00 pm
Location: Columbus Ohio

Postby Lutz » Tue Oct 22, 2002 3:30 pm

Lutz
 
Posts: 5279
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California

Postby CaveGuy » Tue Oct 22, 2002 4:56 pm

CaveGuy
 
Posts: 112
Joined: Sun Oct 13, 2002 3:00 pm
Location: Columbus Ohio

Postby Lutz » Tue Oct 22, 2002 6:38 pm

Lutz
 
Posts: 5279
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California

Postby CaveGuy » Tue Oct 22, 2002 7:38 pm

CaveGuy
 
Posts: 112
Joined: Sun Oct 13, 2002 3:00 pm
Location: Columbus Ohio

Postby Lutz » Tue Oct 22, 2002 8:00 pm

Lutz
 
Posts: 5279
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California

Postby CaveGuy » Tue Oct 22, 2002 9:12 pm

CaveGuy
 
Posts: 112
Joined: Sun Oct 13, 2002 3:00 pm
Location: Columbus Ohio

mysave and myload revisited.

Postby CaveGuy » Sun Oct 27, 2002 3:36 am

;; This is driving me nuts, it should work !!!
;;

(context 'TEST)
(set 'a '("string" 1.1))
(set 'b '("string" 2.2))
(set 'c '("string" 3.3))

(context 'MAIN)

(define (run)
(mysave 'TEST)
(myload 'NEW)
(context 'NEW)
(symbols)
)

(define (mysave mc , fn fh)
(context mc)
(set 'fn "test.lsp")
(set 'fh (open fn "w"))
(dolist (nxt (symbols))
(write-line (append "(set '" (string nxt) " '" (string (eval nxt)) ")" ) fh) )
(close fh)
(set 'fn "test.dat")
(set 'fh (open fn "w"))
(dolist (nxt (symbols))
(write-line (encrypt (append "(set '" (string nxt) " '" (string (eval nxt)) ")" ) "my-key-string") fh) )
(close fh) )

(define (myload mc, fn)
(context mc)
(set 'fn "test.dat")
(set 'fh (open fn "r"))
(while (read-line fh)
(set 'is (encrypt (current-line) "my-key-string"))
(print is "\n") ; first it needs to look ok
;; (eval-string is) ; before we can try to eval it.
)
(close fh) )

;; end of test
CaveGuy
 
Posts: 112
Joined: Sun Oct 13, 2002 3:00 pm
Location: Columbus Ohio

Postby Lutz » Sun Oct 27, 2002 5:29 am

The 'context' primitive works like a compile directive controlling the creation of symbols in certain context while parsing newLISP source code. Use the 'context' primitive only on the toplevel, but don't switch context on runtime. If you have to refer to a symbol in a different context during runtime use i.e.:

(set 'MYCTX:var 123)

this could be embedded in a function without a problem

or

(define (OTHER:proc) .......)

would define proc in the context OTHER, but variables used in OTHER:proc would all refer to the context under which the (define (OTHER:proc) ...) was compiled.

or

(symbols 'ACTX) ; get all the symbols contained in context 'ACTX.

Imagine the following program:

(context 'MAIN)
(define (run) (context 'CTX) (set 'var 123))

MAIN:var => 123

when you run this program, the comand prompt will come back with the context CTX. Because the statement (context 'CTX) switched the "current" context to CTX. But the variable "var" was still compiled under the context 'MAIN, when the function was loaded from a file or entered on the command line. the symbol "var" will be part of MAIN and not CTX.

But now lets load the following program (or enter it on the commandline):

(context 'MAIN)
(define (run) (context 'CTX) (eval-string "(set 'var 123)"))

CTX:var => 123

At this time "var" will be created in the context CTX and not in MAIN. Because "var" doesn't get compiled until runtime of the function 'run' because the compilation is done by the 'eval-string' statement. Now at runtime the "compile context" gets switched to CTX and has an effect on the 'eval-string' statement.

Another more complete example:

(context 'CTX) ;; step A
(set 'var 123) ;; step B
(context 'MAIN) ;; step C
(define (run) (context 'CTX) (set 'var 999)) ;; step D
(run) ;; step E

CTX:var => 123
MAIN:var => 999

step B: At this time CTX:var will be set to 123.
step D: At this time MAIN:var will be created
step E: At this time MAIN:var will be set to 999 and CTX:var stays 123
also after E the current compile context is switched to CTX (not after step D, but after step E)

The function 'symbols' aleays reports the symbols of the "compile context" that is why:

(define (run) (context 'CTX) (symbols))

will report the symbols in CTX. You can use (symbols 'CTX) to accomplish the same without switching contexts.

The background of all this is the fact that newLISP is not and interpreted language, but rather a compiled language. One S-expression at a time gets read in, compiled and then evaluated.

When you read in a function definition with 'define' all symbols occurring in that 'define' statement get compiled into the current context, which had been switched by a '(context 'BLAH) on the top level before. After that a 'define' function statement gets read then executed. Execution here means a lambda expression is produced for the symbol defined. It does not mean that the '(context 'XYZ)' statement, which happens to be part of the 'define' statement has been excuted. It doesn't go into effect until the defined function is called from somewhere.

If you want to switch contexts during function execution time, you really have to know what you are doing (changing the compile context). That is why I recommend using 'context' only on the toplevel. Functions like 'symbols', 'symbol' and 'save' can take an optional context argument.


Lutz

PS: There is also a chapter about 'context' issues in the manual. This chapter talks about the fact that symbols may already have been created in MAIN by the time a context gets loaded compiled. In this case symbols occurring in context will refer to MAIN and not be newly created in the context. When in doubt what symbol is referred to, always prefix with the context name.
Lutz
 
Posts: 5279
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California

My problem is a string incompatibility.

Postby CaveGuy » Sun Oct 27, 2002 6:31 am

I understand what you are saying about contexts. My problem is not with the context games I am playing it is a more basic problem in the fact that

(!= (write-line (encrypt string key) file)
(encrypt (current-line) key) => true
when (read-line file) is used.

For some reason the string read is not the same
as the string written. (encrypt will take a perfectively valid char string and turn it into a binary string
that is very likely to blow up in the string parser during the read-line or write-line for any one of a number of reasons.

I do understand one needs to be very careful when
swapping, saveing and loading contexts on the fly.
CaveGuy
 
Posts: 112
Joined: Sun Oct 13, 2002 3:00 pm
Location: Columbus Ohio

Postby Lutz » Mon Oct 28, 2002 4:16 pm

Lutz
 
Posts: 5279
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California


Return to newLISP in the real world

Who is online

Users browsing this forum: No registered users and 1 guest

cron