surprise: context, constant, and global interaction

Started by TedWalther, May 29, 2015, 12:34:49 AM

Previous topic - Next topic

TedWalther

I was expecting that if a symbol is declared global, then all contexts will treat it as local.  Not so:



(global 'foo)
(context 'bar)
(constant 'foo 2)
=> ERR: symbol not in current context in function constant : foo


I know the manual says this:


Quote
 Only symbols from the current context can be used with constant. This prevents the overwriting of symbols that have been protected in their home context.


But if something is global, doesn't that change the rules a bit?
Cavemen in bearskins invaded the ivory towers of Artificial Intelligence.  Nine months later, they left with a baby named newLISP.  The women of the ivory towers wept and wailed.  \"Abomination!\" they cried.

Lutz

#1
Good practice would be to make a symbol global and constant in the beginning and in MAIN. then leave it constant, if global or not. Both, symbol scope and protection, are major attributes of a symbol which shouldn't be changed.



Most of these rules were introduced and refined when working in a 9-people programming team in 2005/6. A bigger application was partitioned in context modules, which were assigned to specific team members. The person maintaining MAIN was the lead and integrator.





Ps: ... but if you must, you still can do it in this not obvious way:
(eval-string "(constant 'foo 2)" MAIN)

TedWalther

#2
Yes, it took me a few weeks to learn that, but then the Heisenbugs stopped. :-)
Cavemen in bearskins invaded the ivory towers of Artificial Intelligence.  Nine months later, they left with a baby named newLISP.  The women of the ivory towers wept and wailed.  \"Abomination!\" they cried.