Studip question about (context):

Started by alex, February 02, 2006, 10:48:01 AM

Previous topic - Next topic

alex

What are reasons, that (context) is switch?

Why (context) is not standart lisp function?

Why we use

(context 'BLA-BLA-BLA)
  ..............
(context 'MAIN)

against

(context 'BLA-BLA-BLA
  ....................
)

?

Lutz

#1
When newLISP loads it has a compile and evaluation phase. Each toplevel expression in a file gets at first compiled to an internal representation, then evaluated by an internal VM. Writing contexts in a functional manner, would break the separation of compile versus evaluation phase.



The toplevel (context 'FOO) declaration works like a compiler directive switching to a different name space (symbol tree).



The closure effect of the namespace is established during code translation not during run-time, as is the case i.e. in Scheme.



The way how contexts work went through some changes during the current series of development releases, to give it a more intuitive feel. The change was prompted by the experience working with newLISP in a group of programmers (all new to newLISP) and on a bigger multi-module distributed application.



These are in short the differences:



OLD: the runtime context is always the context where the original toplevel function is called from.

NEW: the runtime context is the context the function is written/compiled in (v.8.7.9):



(set 'x 123)
(context 'CTX)

(set 'x 456)

(define (foo) (context))

(define (bar) (eval-string "x"))

(context 'MAIN)

; OLD
(CTX:foo) => MAIN
(CTX:bar) => 123
; NEW
(CTX:foo) => CTX
(CTX:bar) => 456


OLD: In (load myfile) the code in myfile will be in the runtime context of caller, except when a (context ...) statement in 'myfile' switches it. The context after (load ...) returns may be changed.



NEW:If not specified differently in 'mylfile' myfile will always be translated for MAIN, but when (load ...) returns, the runtime context will always be the same as before the (load ...) statement regardless, of what happened inside 'myfile' (v. 8.7.11)



The changes in the context model only effect 'load', 'eval-string', 'net-eval' and 'sym' (when used without the context parameter). Most of anybody's code will not need changes. In all apps. published by newlisp.org only 'cgi.lsp' has changed.



The newer model seems to be more intuitive and behaves more like people expect it. The newer model also offers a better isolation of the context from the context-environment it is called into from.



These are the differences to other LISPs:

When using contexts for object oriented programming in newLISP all objects have to be bound to a symbol, but context-symbols can be assigned to variables and context-objects can be created and deleted during run-time. In Scheme and most other LISPs the object is defined by a lambda closure duing runtime and can stay anonymous. I believe that namespaces are easier to understand than lambda (static) closures.



Contexts as they appear in the next official release 8.8 are described in the manual for 8.7.11 (due coming weekend) you can see a revision of it here http://newlisp.org/downloads/development/Nigel/newlisp_manual.html">http://newlisp.org/downloads/developmen ... anual.html">http://newlisp.org/downloads/development/Nigel/newlisp_manual.html (updated this morning).



Lutz



ps: this post will be part of the 8.8.0 release notes.

alex

#2
I can't express my mind in english enough,

but it is very interesting information not only for me :-)