Howto Solve Context Collision
Posted: Wed Mar 20, 2013 4:45 am
I am new to newLISP, and just can't find out how to solve this problem.
As we know, we can surround a macro to avoid variable capture.
But if we write two diffierent modules without knowing the other one, we might
encounter a context collision, i.e. useing the same name for context.
here is an example:
In module 'A', we define a macro 'my-set' and put it in context 'my-set'(just to illustrate).
And now we write module 'B' without recognizing the existence of module 'A'.
Now we see that we have two implementations of 'my-set' macro in the same
context, if we load these two files at the same time, one will break the other.
if we load 'A.lsp' first, and then 'B.lsp', then the definition of 'my-set' in
B will overwrite that in 'A.lsp', so the 'my-test' function in 'A.lsp' will
fail.
Cause contexts can be seen globally instead of being shadowed by the other
contexts. And we might be using different modules written by different people,
and somehow they might have context collision, and I just wondering how to deal
with this situation.
As we know, we can surround a macro to avoid variable capture.
But if we write two diffierent modules without knowing the other one, we might
encounter a context collision, i.e. useing the same name for context.
here is an example:
In module 'A', we define a macro 'my-set' and put it in context 'my-set'(just to illustrate).
Code: Select all
; A.lsp
(context 'my-set)
(define-macro (my-set a b)
(set (eval a) b))
(context MAIN)
(context 'A)
(define (my-test x)
(letex (x x) (my-set:my-set 'y x)))
(context MAIN)
Code: Select all
; B.lsp
(context 'my-set)
(define-macro (my-set a b)
(set (eval b) a))
(context MAIN)
(context 'B)
(define (my-test x)
(letex (x x) (my-set:my-set x 'y)))
(context MAIN)
context, if we load these two files at the same time, one will break the other.
if we load 'A.lsp' first, and then 'B.lsp', then the definition of 'my-set' in
B will overwrite that in 'A.lsp', so the 'my-test' function in 'A.lsp' will
fail.
Cause contexts can be seen globally instead of being shadowed by the other
contexts. And we might be using different modules written by different people,
and somehow they might have context collision, and I just wondering how to deal
with this situation.