surprise: context, constant, and global interaction

Q&A's, tips, howto's

surprise: context, constant, and global interaction

Postby TedWalther » Fri May 29, 2015 7:34 am

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.
TedWalther
 
Posts: 605
Joined: Mon Feb 05, 2007 1:04 am
Location: Abbotsford, BC

Re: surprise: context, constant, and global interaction

Postby Lutz » Fri May 29, 2015 8:26 pm

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)
Lutz
 
Posts: 5276
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California

Re: surprise: context, constant, and global interaction

Postby TedWalther » Fri May 29, 2015 9:41 pm

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.
TedWalther
 
Posts: 605
Joined: Mon Feb 05, 2007 1:04 am
Location: Abbotsford, BC


Return to newLISP in the real world

Who is online

Users browsing this forum: No registered users and 1 guest

cron