Disappearing functions

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
Jul 1, 2008
81
0
71
Montreal
#1
Windows XP SP 3, TCC 10.00 build 67, registered to Peter Bratton

When I ran this batch file today for the first time in a loong time, I was surprised to discover a new "feature": disappearing functions. If it's not just me, you'll see it right away by stepping through this snippet in the debugger while watching the functions window

setlocal
function divnum=`%@instr[%@index[125,%@left[1,%1]],1,xno]`
function divname=`%@instr[%@eval[6 * %@index[xno,%1]],6,FX Natur Outlet]`
type %listdir\adresses.lst | tr -d ! > %tmp\adresses.lst

As the functions are declared, they are displayed in the watch window, but they both vanish the moment the pipe is executed.

Removing the setlocal command does not change the behaviour.
Moving the setlocal command below the function declarations does not change the behaviour.
A third function, not shown here but declared in 4start.btm, is not affected.

If I change the last line to

do txt in @%listdir\adresses.lst
echo %@strip[!,%txt] >> %tmp\adresses.lst
enddo

the functions remain, which suggests that something is amiss in the transfer of information between shells.

To get around the glitch I put the function declarations after the pipe.

A final observation, setlocal/endlocal fails to clear the functions. I have to "unfunction divnum divname" before quitting the batch file, otherwise the functions live on into the primary shell.
--
Peter
 

rconn

Administrator
Staff member
May 14, 2008
10,203
86
#2
Peter Bratton wrote:


> When I ran this batch file today for the first time in a loong time, I was surprised to discover a new "feature": disappearing functions. If it's not just me, you'll see it right away by stepping through this snippet in the debugger while watching the functions window
>
> setlocal
> function divnum=`%@instr[%@index[125,%@left[1,%1]],1,xno]`
> function divname=`%@instr[%@eval[6 * %@index[xno,%1]],6,FX Natur Outlet]`
> type %listdir\adresses.lst | tr -d ! > %tmp\adresses.lst
>
> As the functions are declared, they are displayed in the watch window, but they both vanish the moment the pipe is executed.
Not reproducible here. Do you have a TCSTART (which will be invoked by
the child pipe process)?


> A final observation, setlocal/endlocal fails to clear the functions. I have to "unfunction divnum divname" before quitting the batch file, otherwise the functions live on into the primary shell.
WAD - SETLOCAL does not affect functions (see the help).

Rex Conn
JP Software