However, this does not work if the original proc is compiled. Rename
does not work either, since I would need to make a copy of the
original, and leave the original intact.
Is there a way to achieve this?
You may find "interp alias" useful (see interp manpage). In your case:
interp alias {} newname {} procname
where {} refer to current interpreter. E.g.:
% interp alias {} print {} puts
print
% print hello
hello
Note however this is not exactly a copy, but an alias. If original
procedure is deleted or modified, newname will be modified/undefined either.
Eric
-----
Eric Hassold
Evolane - http://www.evolane.com/
When you say "copy" or "duplicate", what exactly are you trying to do?
Do you just need identical functionality with a different name? Do you
plan on modifying the copy?
In other words, do you truly need a copy or can other solutions work?
For example, you can use interp aliases to use more than one name, or
command overloading (essentially, renaming and then writing your own
wrapper to call the original) to add new functionality.
--
Bryan Oakley
http://www.tclscripting.com
This is exactly what I was looking for. Thanks a lot!
What I was looking for was essentially command overloading. I did not
want to define a wrapper function primarily because this particular one
gets called a lot within a double nested loop of matrix calculations.
It works just fine now, and I was worried about a negative impact on
efficiency, which may or may not be valid at this early stage.
Interp aliases seem to do exactly what I wanted.
Thanks!
There is one other way to achieve this effect (with all the same caveats
but a slightly different performance profile):
namespace export procname ;# If you haven't already
namespace eval ::tmp { ;# This is arbitrary
namespace import ::procname
rename procname ::newname
namespace delete [namespace current]
}
Note that with this sort of alias, if you delete the original then the
alias completely vanishes as well. This is distinct from the kind of
aliases created with [interp alias].
Donal.
Ugh, I should review the comments more carefully before posting. I meant
to say that the namespace name is arbitrary, but it reads like the whole
line of code is totally arbitrary. Goes to show I shouldn't post at that
time of night. (The code itself is correct though.)
Donal.
Thanks for the clarification. I have not done much with namespaces
yet, but I will keep this in mind for new projects.
> There is one other way to achieve this effect (with all the same caveats
> but a slightly different performance profile):
>
> namespace export procname ;# If you haven't already
> namespace eval ::tmp { ;# This is arbitrary
> namespace import ::procname
> rename procname ::newname
> namespace delete [namespace current]
> }
>
> Note that with this sort of alias, if you delete the original then the
> alias completely vanishes as well. This is distinct from the kind of
> aliases created with [interp alias].
Wow. I've never thought of that. I learned something mind-alteringly
cool and I'm not even in Naperville yet. :-D
Michael
I wish I'd been the one to invent it, but I actually copied the
technique out of the Tk test suite. :-)
Donal.