473,757 Members | 6,899 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Altering the namespace of the calling function

Hi,

First off I know that in almost all cases this would be a terrible thing to
do, but this is an unusual case where this makes sense.

Basically I have a procedure where you pass a string containting a template
for a tuple, the function then finds a tuple that matches this template and
then returns it. The template may contain variable names, which match
against anything in that position in the tuple - this is all working fine,
except that I would like a variable to be created in the caller's scope by
the matching function.

I can retrieve the scope of the calling function using
sys._getframe(1 ).f_locals however whenever I try to modify it the changes
are made but the variable doesn't match to the new variable in the scope. I
tried creating a variable of the same name before calling the matching
function, but when the matching function returns the changes to the scope
for that variable are discarded.

Can anyone suggest how to make this work?
Andrew Wilkinson

Jul 18 '05 #1
1 2163
Andrew Wilkinson asks:
except that I would like a variable to be created in the caller's scope by
the matching function.
Pass in a mutable or use return. The obvious intent is to use this in the
calling routine, and you're asking how to change the called routine, so
you've got access to both.

I can retrieve the scope of the calling function using
sys._getframe(1 ).f_locals however whenever I try to modify it the changes
are made but the variable doesn't match to the new variable in the scope. I

No surprise here. From the manual:
"The contents of this dictionary should not be modified; changes may not
affect the values of local variables used by the interpreter. "

tried creating a variable of the same name before calling the matching
function, but when the matching function returns the changes to the scope
for that variable are discarded.

Can anyone suggest how to make this work?


If both routines are within the same global module scope, you could use
global. If not, you could hang shared variables on a mutually imported
module.

HTH,

Emile van Sebille
em***@fenx.com

Jul 18 '05 #2

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

Similar topics

8
2076
by: Elaine Jackson | last post by:
I would like to be able to write a function f, which will live in a module M, and will call a function g, such that, when f is imported from M into the interpreter, and invoked there, its invokation of g will return the interpreter's global namespace. Is there a way to do this and, if so, how? Muchas gracias for any and all assistance. Peace
7
1462
by: vegetax | last post by:
I i need a decorator that adds a local variable in the function it decorates, probably related with nested scopes, for example: def dec(func): def wrapper(obj = None): if not obj : obj = Obj() <bind obj to func> return func() return wrapper()
2
1845
by: Karthik Kumar | last post by:
Hi, I was writing this application that used namespaces. The structure of the file was as follows. //Header file #ifndef MYNS_MYHEADER_H #define MYNS_MYHEADER_H
4
3083
by: Kevin Newman | last post by:
The primary problem I've had with php is the lack of namespaces, which makes OOP very difficult to organize, since you end up with large number of classes cluttering up the same namespace - which leads to a secondary problem involving php's __autoload feature. Since you cannot specify a namespace when calling a class that may not have been included, you are forced to store all of your classes in the same folder in your file system. This...
30
4117
by: Pep | last post by:
Is it best to include the code "using namespace std;" in the source or should each keyword in the std namespace be qualified by the namespace tag, such as std::cout << "using std namespace" << std::endl; Myself I am not sure which I prefer, it is certainly easier to specify that the std namespace is being used instead of tagging each member of the namespace?
3
7826
by: Frederick Gotham | last post by:
Back in the day, if you wanted a function to be self-contained within a translation unit, you defined the function as "static". If there were an external linkage function by the same name residing in a different translation unit, then the current translation unit was simply oblivious to it and had no way of accessing it. Any time the function name was mentioned in the current translation unit, it referred to the "static" one which...
2
1764
by: Safalra | last post by:
The problem below is obviously some sort of namespace clash, but I don't understand exactly why - can anyone explain? Take the following simple Javascript code: <script type="text/javascript"> function scrollLeft(){ alert('scrollLeft') }; function scrollLeft2(){ alert('scrollLeft2') }; scrollLeft(); scrollLeft2(); </script>
9
8390
by: JimmyKoolPantz | last post by:
IDE: Visual Studio 2005 Language: VB.NET Fox Pro Driver Version: 9.0.0.3504 Problem: I currently have a problem altering a DBF file. I do not get any syntax errors when running the program. However, after I alter the table and open microsoft excel to look at any changes; I get the following error: "This file is not in a recognizable format" If I do open the file in excel it looks like its not formatted.
12
5410
by: Taras_96 | last post by:
Hi everyone, AFAIK external linkage allows you to refer to variables/functions outside of the current translation unit. A variable in an unnamed namespace is similar to declaring a static variable, but according to the standard there is a difference: "While this is essentially true in practical effect, there are subtle differences. Using static as shown here causes "i" to have internal
0
9298
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10072
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9906
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9737
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8737
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7286
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6562
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5172
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3829
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.