thanks Damon

 I always thought one of Tcl's greatest perks was its extreme
flexibility, and I'm rather sure over the years several times I came
across examples where core commands were renamed (perhaps also on
TCLCORE?). My implementation was to return what ::tcl::info::* returns
except when 'info script' is called

Anyway...never mind...If you suggest so I will take no chance on this.

Earlier today Harald wrote a private message where he's pointed out
exactly what you said: info core command is an ensemble.

As a matter of fact I answered asking if I had to replace
::tcl::info::script (option 1) and he replied I had to exploit the
'namespace ensemble -map' construct! So...agreement on option 2 is even
stronger as we converged to the same point independently.


 thanks

 -- Massimo

On 01/20/2014 06:29 PM, Damon Courtney wrote:
> Ugh.  Don’t do that at all.  Overriding Tcl’s [info] command (or any
> core commands) by renaming and replacing is a path to doom.
> 
> The good news is that we no longer have to.  As of 8.5.something,
> [info] is a namespace ensemble command.  I do think it’s worthwhile
> to make [info script] do the right thing, so you have two ways of
> doing it.
> 
> Option 1
> 
> proc ::tcl::info::script {{filename “”}} { return [::rivet::env
> SCRIPT_FILENAME] }
> 
> This replaces Tcl’s call for the [info script] command with a proc of
> our own making that just returns our script no matter what while
> maintaining the same call structure for compatibility.  But it
> overwrites a Tcl core function, even if it is buried behind an
> ensemble.
> 
> Option 2
> 
> proc ::rivet::InfoScript {{filename “”}} { return [::rivet::env
> SCRIPT_FILENAME] }
> 
> set map [namespace ensemble configure ::info -map] dict set map
> script ::rivet::InfoScript namespace ensemble configure ::info -map
> $map
> 
> Option 2 obviously has a few more steps, but is probably more
> correct.  Anyone looking at the ensemble can immediately tell we’ve
> overridden the script command.  They can also still reach the
> original [info script] command by calling ::tcl::info::script if they
> want.  It actually does more than just tell you the startup script.
> :)
> 
> Damon
> 
> 


-- 
-- Massimo Manghi

Dipartimento di Neuroscienze
Unità di Biofisica e Fisica Medica
via Volturno 39
43125 Parma

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to