Re: (newbie) storing outputs from all lines of procs into a string
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.tcl archive

Re: (newbie) storing outputs from all lines of procs into a string

From: Bryan Oakley <oakley@bardo.clearlight.com>
Date: Mon Dec 19 2005 - 17:56:57 CET

just80n@gmail.com wrote:
> I'll use this one but following code :
>
> proc ex {COMMAND} {
> set OUTPUT ""
> rename puts _puts
> proc puts {args} { append OUTPUT $args "\n"; eval _puts $args }
> eval $COMMAND
> rename _puts puts
> return $OUTPUT
> }
> ...
> can't rename to "puts": command already exists
>
>
> in other words " rename _puts puts " fails.... a workaround?
>

You can't rename something, giving it a name of an existing proc. In
your code you have created a proc named 'puts', so you can't rename
_puts to puts. Remember that procs aren't local; they are global. Even
though you rename puts inside a proc it has a global effect.

The workaround is to either a) only redefine puts once outside the
definition of ex, or b) remove the 'puts' proc (rename puts {}) before
renaming _puts".

I'd vote for a. Is there a reason you want to continually rename puts?
Received on Fri Dec 23 19:02:15 2005