Page 1 of 1
Illegal symbols cannot restore
Posted: Mon Mar 15, 2010 12:09 pm
by kosh
Code: Select all
newLISP v.10.1.12 on Linux IPv4 UTF-8, execute 'newlisp -h' for more info.
> (legal? "#")
nil
> (new Tree (sym "#")) ; make context `#'
> (set (sym "one" (sym "#")) 1) ; `#:one' = 1
> (set (sym "two" (sym "#")) 2) ; `#:two' = 2
> (source (sym "#"))
"\n(context '#)\n\n(set 'one 1)\n\n(set 'two 2)\n\n\n(context MAIN)\n\n"
> (eval-string (source (sym "#")))
ERR: missing parenthesis : "...'one 1)\n\n(set 'two 2)\n\n\n(context MAI"
Therefore, `save/load' function cannot use illegal symbol too.
Code: Select all
(save "_hash.lsp" (sym "#"))
(load "_hash.lsp") ;-> ERR: missing parenthesis
--- kosh
Re: Illegal symbols cannot restore
Posted: Mon Mar 15, 2010 12:34 pm
by Lutz
Thanks Kosh, this will be corrected for illegal symbols in contexts. But only context symbols should be forced to be legal. For other symbols it still must be allowed, as it is currently needed, i.e. to save hash name-spaces:
Code: Select all
> (new Tree 'Foo)
Foo
> (Foo "# & % " 123)
123
> (save "Foo.lsp" 'Foo)
true
> !cat Foo.lsp
(context 'Foo)
(set (sym "_# & % " MAIN:Foo) 123)
(context MAIN)
> (load "Foo.lsp")
MAIN
> (Foo "# & % ")
123
>
ps: in case anybody gets confused by this:
on Windows you would do:
The '!' as first character on the command-line shells out into the OS.
Re: Illegal symbols cannot restore
Posted: Tue Mar 16, 2010 3:47 pm
by kosh
Thanks Lutz. I'm looking forward to next version release.
On another note the report added about illegal symbol.
Code: Select all
> (legal? (uuid))
nil
> (define (gensym) (sym (uuid))) ; make unique symbol use `uuid'
> (letex (s (gensym) v (gensym))
(define-macro (my-setq s v)
(set s (eval v))))
> (print (source 'my-setq))
(define-macro (my-setq 40DD3B92-C5D0-4E3D-BF2C-E63B963DD69B 4596AFF8-31F8-487B-B302-5149CD44AEED)
(set 40DD3B92-C5D0-4E3D-BF2C-E63B963DD69B (eval 4596AFF8-31F8-487B-B302-5149CD44AEED)))
> (read-expr (source 'my-setq))
; symbol name separated!
(define-macro (my-setq 40 DD3B92-C5D0-4E3D-BF2C-E63B963DD69B 4596 AFF8-31F8-487B-B302-5149CD44AEED)
(set 40 DD3B92-C5D0-4E3D-BF2C-E63B963DD69B (eval 4596 AFF8-31F8-487B-B302-5149CD44AEED)))
But, to resolve this problem in several ways.
Code: Select all
;; 1. use legal symbol
(define (gensym)
(sym (string "g-" (uuid)))) ; 'g-*** will be legal symbol
;; 2. use context
(context 'gensym)
(define (gensym:gensym)
(inc *counter*)
(sym (string "g-" *counter*))) ; MAIN:g-***,gensym:g-*** will NOT conflict namespace
(context MAIN)
;; 3. use `args' function
(define-macro (my-setq )
(set (args 0) (eval (args 1))))
--- kosh
Re: Illegal symbols cannot restore
Posted: Tue Mar 16, 2010 4:57 pm
by Lutz
Speed performance wise solutions 3. is the best. Or put the define-macro definition inside its own context to protect against variable capture.
Code: Select all
(context 'my-setq)
(define-macro (my-setq:my-setq x v)
(set x (eval v)))
(context MAIN)