Hi group,it doesnt end up in recursive call.
Below I have a proc called orig_proc and am renaming it to a new_proc. But once I rename it the orig_proc doesnt exist anymore. But the orig_proc is needed to be called by other procs also. So How do I rename the new_proc back to orig_proc
proc orig_proc {} {
puts "in original proc"
}
rename -force orig_proc new_proc
proc orig_proc {} {
eval new_proc // here instead of executing new_proc, I want new_proc to be renamed back to orig_proc
m() // because m() calls the orig_proc in its definition and it runs into a recursive call which needs to be avoided, so I need new_proc to be renamed back to orig_proc
}
How to rename the new_proc back to orig_proc once again?
In the first step I renamed the orig_proc, because I wanted m() also to be called in orig_proc's new definition. So i renamed it , but now within orig_proc redefinition i need it back to be renamed to its orig_proc name so that m() calls orig_proc and
Do you really need to play ping pong with the proc name, or do youand it doesnt end up in recursive call.
rather want to be able to call the procedure by both names?
Maybe it would help to create an alias of the procedure, so you can
leave it in its own name, and still access it by another name, too:
Look at https://wiki.tcl-lang.org/page/namespace and search for
section "Make an Alias for a Command"
Kavitha MS <kavit...@gmail.com> wrote:
Hi group,
Below I have a proc called orig_proc and am renaming it to a new_proc. But once I rename it the orig_proc doesnt exist anymore. But the orig_proc is needed to be called by other procs also. So How do I rename the new_proc back to orig_proc
proc orig_proc {} {
puts "in original proc"
}
rename -force orig_proc new_proc
proc orig_proc {} {
eval new_proc // here instead of executing new_proc, I want new_proc to be renamed back to orig_proc
m() // because m() calls the orig_proc in its definition and it runs into a recursive call which needs to be avoided, so I need new_proc to be renamed back to orig_proc
}
How to rename the new_proc back to orig_proc once again?
In the first step I renamed the orig_proc, because I wanted m() also to be called in orig_proc's new definition. So i renamed it , but now within orig_proc redefinition i need it back to be renamed to its orig_proc name so that m() calls orig_proc
On Monday, August 14, 2023 at 3:21:56 AM UTC+5:30, Andreas Leitgeb wrote:and it doesnt end up in recursive call.
Do you really need to play ping pong with the proc name, or do you
rather want to be able to call the procedure by both names?
Maybe it would help to create an alias of the procedure, so you can
leave it in its own name, and still access it by another name, too:
Look at https://wiki.tcl-lang.org/page/namespace and search for
section "Make an Alias for a Command"
Kavitha MS <kavit...@gmail.com> wrote:
Hi group,
Below I have a proc called orig_proc and am renaming it to a new_proc. But once I rename it the orig_proc doesnt exist anymore. But the orig_proc is needed to be called by other procs also. So How do I rename the new_proc back to orig_proc
proc orig_proc {} {
puts "in original proc"
}
rename -force orig_proc new_proc
proc orig_proc {} {
eval new_proc // here instead of executing new_proc, I want new_proc to be renamed back to orig_proc
m() // because m() calls the orig_proc in its definition and it runs into a recursive call which needs to be avoided, so I need new_proc to be renamed back to orig_proc
}
How to rename the new_proc back to orig_proc once again?
In the first step I renamed the orig_proc, because I wanted m() also to be called in orig_proc's new definition. So i renamed it , but now within orig_proc redefinition i need it back to be renamed to its orig_proc name so that m() calls orig_proc
Creating alias will make both names to be pointing to same proc orig_proc, but my intention of renaming the orig_proc is to redefine it to accomodate a new API call m1() in addition to its original definition. That's y I didnt think of creating analias. Because old definition of orig_proc and new definition of renamed orig_proc will differ in their functionality. But m() internally calls orig_proc in its definition and since I have renamed orig_proc, it again tries to rename it which leads to a
proc orig_proc {} {
puts "in original proc"
}
rename -force orig_proc new_proc
proc orig_proc {} {
rename new_proc orig_proc // here new_proc should be renamed back to orig_proc
m() // because m() calls the orig_proc in its definition and it runs into a recursive call which needs to be avoided, so I need new_proc to be renamed back to orig_proc
}
I've guessed the actual problem is that method_m code really needs to
always call the original version of func, but could be called both
before and after the rename takes place.
et99 <et99@rocketship1.me> wrote:
I've guessed the actual problem is that method_m code really needs to
always call the original version of func, but could be called both
before and after the rename takes place.
Which is the problem, much of this thread is still *guesswork* on our
part.
It so far has the feeling of the OP asking us to make work his specific solution to a problem, without telling us anything about the actual
problem the solution is meant to solve. And if we were told the actual problem there might be a very different solution that is more workable
than the given solution.
On 8/14/2023 12:29 PM, Rich wrote:it incorrectly. That and his use of C++ like comments and () as part of proc/function names intermixed in Tcl code.
et99 <et...@rocketship1.me> wrote:
I've guessed the actual problem is that method_m code really needs to
always call the original version of func, but could be called both
before and after the rename takes place.
Which is the problem, much of this thread is still *guesswork* on our part.
It so far has the feeling of the OP asking us to make work his specific solution to a problem, without telling us anything about the actual problem the solution is meant to solve. And if we were told the actual problem there might be a very different solution that is more workable than the given solution.
I didn't have a clue about this thread until I stumbled upon an earlier thread by the same OP that only appears when I use Thunderbird. It's also started on 8/12.
In that posting, it seemed to suggest he was trying to create a wrapper that would add something to an existing proc. That post seems clear, although I suspect the OP is a C/C++ programmer somewhat new to Tcl. For example, he knows about {*} but uses
It remains to be seen if my guess was correct, however.
You can rename the proc *while you're in it* just fine:
* Kavitha MS <kavit...@gmail.com>
| proc orig_proc {} {
| puts "in original proc"
| }
| rename -force orig_proc new_proc
| proc orig_proc {} {
| eval new_proc // here instead of executing new_proc, I want new_proc to be renamed back to orig_proc
| m() // because m() calls the orig_proc in its definition and it runs into a recursive call which needs to be avoided, so I need new_proc to be renamed back to orig_proc
| }
| How to rename the new_proc back to orig_proc once again?
| In the first step I renamed the orig_proc, because I wanted m() also
| to be called in orig_proc's new definition. So i renamed it , but now
| within orig_proc redefinition i need it back to be renamed to its
| orig_proc name so that m() calls orig_proc and it doesnt end up in
| recursive call.
You can rename the proc *while you're in it* just fine:
proc orig_proc {} {
puts "in original proc"
}
proc m {} {
orig_proc
}
rename orig_proc new_proc
proc orig_proc {} {
puts "in temp orig_proc"
new_proc
rename orig_proc ""
rename new_proc orig_proc
m
}
% orig_procThank you. It worked
in temp orig_proc
in original proc
in original proc
(Note that my tcl 8.6 has no "rename -force", so I need to delete the orig_proc before I can override it again.)
R'
On Tuesday, August 15, 2023 at 1:38:53 AM UTC+5:30, et99 wrote:it incorrectly. That and his use of C++ like comments and () as part of proc/function names intermixed in Tcl code.
On 8/14/2023 12:29 PM, Rich wrote:
et99 <et...@rocketship1.me> wrote:I didn't have a clue about this thread until I stumbled upon an earlier thread by the same OP that only appears when I use Thunderbird. It's also started on 8/12.
I've guessed the actual problem is that method_m code really needs to
always call the original version of func, but could be called both
before and after the rename takes place.
Which is the problem, much of this thread is still *guesswork* on our
part.
It so far has the feeling of the OP asking us to make work his specific
solution to a problem, without telling us anything about the actual
problem the solution is meant to solve. And if we were told the actual
problem there might be a very different solution that is more workable
than the given solution.
In that posting, it seemed to suggest he was trying to create a wrapper that would add something to an existing proc. That post seems clear, although I suspect the OP is a C/C++ programmer somewhat new to Tcl. For example, he knows about {*} but uses
It remains to be seen if my guess was correct, however.
Hi,
Your guess is right. I am new to tcl scripting. Its a tendency to use C/C++ coding syntax since I am used to that. That 's y by mistake i had used m().
And solution provided by Ralf Fassel worked for me
You can rename the proc *while you're in it* just fine:
proc orig_proc {} {
puts "in original proc"
}
proc m {} {
orig_proc
}
rename orig_proc new_proc
proc orig_proc {} {
puts "in temp orig_proc"
new_proc
rename orig_proc ""
rename new_proc orig_proc
m
}
% orig_proc
in temp orig_proc
in original proc
in original proc
With this renaming orig_proc "" (i.e basically deleting it) and then renaming new_proc to orig_proc worked for me.
Thank you all for all the possible solutions provided.
Thanks once again
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 497 |
Nodes: | 16 (2 / 14) |
Uptime: | 07:28:55 |
Calls: | 9,780 |
Calls today: | 21 |
Files: | 13,748 |
D/L today: |
1 files (1K bytes) |
Messages: | 6,186,960 |