> 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 >later. > >unset verbose >chatter "$i" >... >verbose=1 >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. -- Roger http://rogerx.freeshell.org/