473,396 Members | 1,965 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Dynamical scoping

What's the best way to simulate dynamically scoped variables ala
Lisp ? The use case is an open-ended set of objects that need to
access the same piece of information (e.g. a dict, a ConfigParser
object, a logger etc.). I know that the "proper" OO and functional way
is to pass the information explicitly but that's less maintenable in
the long run. Also this is in a web environment so the information
can't be really global (though within-thread global should be fine).
Is there some standard pattern for this scenario ?

George
Jan 14 '08 #1
4 1001
George Sakkis <ge***********@gmail.comwrites:
What's the best way to simulate dynamically scoped variables ala Lisp ?
Ugh.... check the docs for the python 2.5 "with" statement, which
gives you sort of a programmable unwind-protect (more powerful than
try/except). You'd have an environment dictionary and use the "with"
statement to maintain a stack of shallow-binding cells like in an
old-time lisp system, automatically unwinding when the "with" suite
finishes. The whole concept sounds hopelessly crufty--I think nobody
even does it that way in Lisp any more, you're better off passing an
environment around explicitly. If there were a lot of variables, this
could be a good application for functional maps, which I've been wanting
to implemetn for python.
Jan 15 '08 #2
On 15 Jan., 02:13, Paul Rubin <http://phr...@NOSPAM.invalidwrote:
George Sakkis <george.sak...@gmail.comwrites:
What's the best way to simulate dynamically scoped variables ala Lisp ?

Ugh.... check the docs for the python 2.5 "with" statement, which
gives you sort of a programmable unwind-protect (more powerful than
try/except). You'd have an environment dictionary and use the "with"
statement to maintain a stack of shallow-binding cells like in an
old-time lisp system, automatically unwinding when the "with" suite
finishes. The whole concept sounds hopelessly crufty--I think nobody
even does it that way in Lisp any more, you're better off passing an
environment around explicitly. If there were a lot of variables, this
could be a good application for functional maps, which I've been wanting
to implemetn for python.
Jan 15 '08 #3
On 14 Jan., 21:17, George Sakkis <george.sak...@gmail.comwrote:
What's the best way to simulate dynamically scoped variables ala
Lisp ? The use case is an open-ended set of objects that need to
access the same piece of information (e.g. a dict, a ConfigParser
object, a logger etc.). I know that the "proper" OO and functional way
is to pass the information explicitly but that's less maintenable in
the long run. Also this is in a web environment so the information
can't be really global (though within-thread global should be fine).
Is there some standard pattern for this scenario ?

George
What do you mean by "really global" and why is module local or builtin
a problem
in the presence of the GIL? Passing objects as parameters into
functions doesn't
ensure any more thread safety. Where do you think does Lisp ( which
one? ) stores
dynamically scoped variables?
Jan 15 '08 #4
Kay Schluehr <ka**********@gmx.netwrites:
On 15 Jan., 02:13, Paul Rubin <http://phr...@NOSPAM.invalidwrote:
George Sakkis <george.sak...@gmail.comwrites:
What's the best way to simulate dynamically scoped variables ala Lisp ?
Ugh.... check the docs for the python 2.5 "with" statement, which
gives you sort of a programmable unwind-protect (more powerful than
try/except). You'd have an environment dictionary and use the "with"
statement to maintain a stack of shallow-binding cells like in an
old-time lisp system, automatically unwinding when the "with" suite
finishes. The whole concept sounds hopelessly crufty--I think nobody
even does it that way in Lisp any more, you're better off passing an
environment around explicitly. If there were a lot of variables, this
could be a good application for functional maps, which I've been wanting
to implemetn for python.
Kay, did you have something to add? You quoted the above two posts
and then your message stopped.
Jan 15 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: David Stockwell | last post by:
Hi, Another of my crazy questions. I'm just in the process of learning so bear with me if you can. I actually ran it.... with two test cases TEST CASE 1: Say I have the following defined:...
5
by: Sune | last post by:
Hi, I need to replace some dynamical content away from a text, only static thing is that it starts with <!-- Start dynamic --> and ends with <!-- End dynamic -->. How do i dynamical remove these...
0
by: Jacob Kroon | last post by:
Hi, I'm having some problems with implementing dynamical module loading. First let me describe the scenario with an example: modules/ fruit/ __init__.py apple.py banana.py
0
by: paula | last post by:
I've got a problem with asp.net i am trying to make a menu control. and have searched the web for serveral controls but they don't work correctly. I am pretty new to asp.net building. What am i...
4
by: FraterQ | last post by:
Hello, after i've read this post, i tried it myself and it works....
4
by: Joel Gordon | last post by:
Hi, When I try and compile the a class containing the following method : public void doSomething() { for (int i=0; i<5; i++) { IList list = new ArrayList(); Console.WriteLine( i /...
9
by: NevilleDNZ | last post by:
Can anyone explain why "begin B: 123" prints, but 456 doesn't? $ /usr/bin/python2.3 x1x2.py begin A: Pre B: 123 456 begin B: 123 Traceback (most recent call last): File "x1x2.py", line 13,...
3
by: morris.slutsky | last post by:
So every now and then I like to mess around with hobby projects - I often end up trying to write an OpenGL video game. My last attempt aborted due to the difficulty of automating game elements and...
17
by: Chad | last post by:
The following question stems from Static vs Dynamic scoping article in wikipedia. http://en.wikipedia.org/wiki/Scope_(programming)#Static_versus_dynamic_scoping Using this sites example, if I...
3
by: SPECTACULAR | last post by:
Hi all. I have a question here.. what kind of scoping does C++ use? and what kind does Smalltalk use? I know smalltalk is a little bit old .. but any help would be appreciated.
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.