[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Re: Inline `ifdef style` debugging

From: Roger
Subject: Re: Re: Inline `ifdef style` debugging
Date: Thu, 11 Aug 2011 12:38:17 -0800
User-agent: Mutt/1.5.21 (2010-09-15)

> On Thu, Aug 11, 2011 at 08:13:27AM -0400, Greg Wooledge wrote:
>On Thu, Aug 11, 2011 at 12:23:00AM -0700, pjodrr wrote:
>> they call it "collapsing functions":
>> http://wiki.bash-hackers.org/howto/collapsing_functions
>"The first time you run chatter(), the function redefines itself based on the
>value of verbose. Thereafter chatter doesn't check $verbose anymore, it simply
>is. Further calls to the function reflect its collapsed nature. If verbose is
>unset, chatter will echo nothing, with no extra effort from the developer."
>The problem with this is that you can't switch to the other function
>unset verbose
>chatter "$i"
>chatter "$j"
>Here, the first call to chatter blows away the test of $verbose, so
>the next time we call it, the fact that we've set verbose=1 is ignored.
>We're stuck in non-verbose mode forever.

OK. Now I see the collapsing, and it seems more like a hidden collapse rather
then an immediately apparent collapse from an initial stance after
reading/tracing.  When tracing this function, I was thinking the function
would be read each time the top function was called.

In reality, the function is read once during the first read in of the function
(or on script execution), as such, doesn't look like anymore if/thens are called
after the first reading of the function.  It just "is" after the first reading.

Guess I could put a little "reminder comment" when I use collapsible functions
to remind me of this effect, as well as others reading/tracing the script.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]