surprise: context, constant, and global interaction

Q&A's, tips, howto's
Post Reply
TedWalther
Posts: 606
Joined: Mon Feb 05, 2007 1:04 am
Location: Abbotsford, BC
Contact:

surprise: context, constant, and global interaction

Post 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?
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
Posts: 5279
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: surprise: context, constant, and global interaction

Post 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)

TedWalther
Posts: 606
Joined: Mon Feb 05, 2007 1:04 am
Location: Abbotsford, BC
Contact:

Re: surprise: context, constant, and global interaction

Post by TedWalther »

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.

Post Reply