Page 1 of 1

surprise: context, constant, and global interaction

Posted: Fri May 29, 2015 7:34 am
by TedWalther
I was expecting that if a symbol is declared global, then all contexts will treat it as local. Not so:

Code: Select all

(global 'foo)
(context 'bar)
(constant 'foo 2)
=> ERR: symbol not in current context in function constant : foo
I know the manual says this:
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?

Re: surprise: context, constant, and global interaction

Posted: Fri May 29, 2015 8:26 pm
by Lutz
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:

Code: Select all

(eval-string "(constant 'foo 2)" MAIN)

Re: surprise: context, constant, and global interaction

Posted: Fri May 29, 2015 9:41 pm
by TedWalther
Yes, it took me a few weeks to learn that, but then the Heisenbugs stopped. :-)