From: SourceForge.net <no...@so...> - 2003-03-21 09:43:58
|
Bugs item #707104, was opened at 2003-03-20 21:05 You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=110894&aid=707104&group_id=10894 Category: 19. [interp] Group: None Status: Open Resolution: Duplicate Priority: 2 Submitted By: Vince Darley (vincentdarley) Assigned to: miguel sofer (msofer) Summary: [interp alias] commands cannot be [rename]d Initial Comment: I see some very peculiar behaviour with aliased commands, which is at the very least not documented, and possible a bug: % proc foo {} { puts "orig" } % interp alias {} bar {} foo % bar orig % rename bar bar2 % bar2 orig % bar orig # (So now both 'bar' and 'bar2' are aliases, i.e. 'rename' actually copies the alias rather than renaming it) % proc foo2 {} { puts "new" } % interp alias {} bar {} foo2 % bar new % bar2 invalid command name "bar2" # (So the act of creating a new alias "bar" deletes both the old aliases "bar" and "bar2") ---------------------------------------------------------------------- Comment By: Eric Boudaillier (beric) Date: 2003-03-21 10:56 Message: Logged In: YES user_id=493507 Does this help ? It takes care of renaming an alias (restricted in one interp) proc rename_alias {oldCmd newCmd} { set alias [interp alias {} $oldCmd] if {[llength $alias]} { if {$newCmd ne ""} { eval [concat [list interp alias {} $newCmd {}] $alias] } interp alias {} $oldCmd {} } else { rename $oldCmd $newCmd } } ---------------------------------------------------------------------- Comment By: Donal K. Fellows (dkf) Date: 2003-03-21 10:45 Message: Logged In: YES user_id=79902 I agree with Vince here, especially now we've got command traces. ---------------------------------------------------------------------- Comment By: Vince Darley (vincentdarley) Date: 2003-03-21 09:48 Message: Logged In: YES user_id=32170 The 'rename' man page needs updating then to reflect this limitation. It's a shame that aliases don't work in this way, since they are otherwise a very powerful part of Tcl. However, they completely break the semantics of a Tcl command, which is bad! Is there any reason 'interp aliases' can't return the *current* name of the alias, which users can quite happily iterate over. I wouldn't even see this as a back-compatibility issue, but as a bug fix. After all: proc foo {} {} rename foo bar info procs foo # should obviously not return 'foo' So, similarly interp alias {} foo {} implementation rename foo bar interp aliases # should not return foo either ---------------------------------------------------------------------- Comment By: miguel sofer (msofer) Date: 2003-03-20 21:55 Message: Logged In: YES user_id=148712 As noted in http://groups.google.com/groups?hl=en&safe=off&th=1784032ddc241340%2C4&seekm=8mf2uq%24jkq%241%40bob.news.rcn.net this behaviour is ancient (since 7.6). Don's summary of the issue (from the chat): The issue is the [interp aliases] introspection. It always returns the original names of the aliases. So even if there is a [rename], the alias still keeps a connection to its original name, so it can be reached by folks iterating of [interp aliases]. This was a bad choice. If we need a permanent name for [interp aliases] to return, we should have a special token just for that purpose. For now, the practical advice is "you can't [rename] an alias" Low priority to signify "not much can be done about it for now". ---------------------------------------------------------------------- Comment By: miguel sofer (msofer) Date: 2003-03-20 21:26 Message: Logged In: YES user_id=148712 Yup, this is weird ... It is not a new issue in 8.4 (pheww!), it fails already in 8.3.4 % info patch 8.3.4 % proc foo {} { puts "orig" } % interp alias {} bar {} foo bar % bar orig % rename bar bar2 % bar orig % bar2 orig % rename bar {} can't delete "bar": command doesn't exist % bar orig % bar2 orig % rename bar2 {} % bar invalid command name "bar" % bar2 invalid command name "bar2" ---------------------------------------------------------------------- Comment By: Don Porter (dgp) Date: 2003-03-20 21:26 Message: Logged In: YES user_id=80530 This is a known issue, and can't really be corrected unless/until [interp aliases] is changed to return a token. See FR 524140. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=110894&aid=707104&group_id=10894 |