How to? Logic in functions...

May 24, 2010
855
0
Northlake, Il
I found out in another thread that one could place logical statements (if, do while, etc.) into alias definitions, which I didn't know. I would assume, but possibly incorrectly, that one could not do that in function definitions except by executing a batch file via @ExecStr. Am I correct in that assumption?
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,466
88
Albuquerque, NM
prospero.unm.edu
I found out in another thread that one could place logical statements (if, do while, etc.) into alias definitions, which I didn't know. I would assume, but possibly incorrectly, that one could not do that in function definitions except by executing a batch file via @ExecStr. Am I correct in that assumption?

There is the @IF function. Be aware, though, that all of its arguments are evaluated -- regardless of whether the test condition is true or false.
 

samintz

Scott Mintz
May 20, 2008
1,503
16
Solon, OH, USA
Dan, here's an example of using @ExecStr with a DO loop.

Code:
function DoLogic=`%@execstr[SetLocal & Set C=0 & Do I=1 to %1 (Set C=%@inc[c]) & Echo C: %C I: %I & EndLocal]`
 
echo %@DoLogic[500]
C: 500 I: 501

-Scott
 
May 24, 2010
855
0
Northlake, Il
Scott, thank you for both giving me the answer and making me laugh. You effectively did a batch file, you just put it directly into the @ExecStr. Somehow it was in my mind that you could just execute external programs and batch files that way. And looking at the documentation (note Rex) there's not a clue that you can do that (although it certainly doesn't explicitly prohibit either).
 
Similar threads
Thread starter Title Forum Replies Date
M How to? Logic in aliases... Support 3
M How to? Put logic into an alias... Support 6
A Problem with functions @int @decimal and identifying Powershell as a shell. Support 12
Joe Caverly "Functions" in cmd.exe batch files Support 6
vefatica Library functions and line continuations? Support 4
Charles Dye Documentation Help Nits Forever: Checksum functions Support 0
Joe Caverly SETLOCAL removes Aliases and Functions Support 3
Joe Caverly @NAME supports library functions Support 2
Charles Dye Functions which no-one has ever tried to use.... Support 5
vefatica WHICH and @functions Support 2
vefatica Two @FUNCTIONs/aliases with the same name Support 4
M Keywords for commands, functions, internal variables Support 3
C Documentation near or fully obsolete functions Support 7
Charles Dye Optional F parm in checksum functions Support 0
C coding functions and subroutines Support 9
rps Functions @year[date] @isowyear[date] help Support 7
mikea How to? TCC and XMLnodes/XMLxpath functions Support 0
Dan Glynhampton Are these two functions the same? Support 2
A WAD function return values with parentheses prevent evaluation of additional functions Support 31
M "History" command not giving me what I want when executed by @Exec... functions... Support 6
Charles Dye Web help on functions Support 2
samintz Help examples for the @ISxxx functions Support 3
R specific functions for number conversion Support 2
C Unsuppressable errors from XML functions Support 5
nikbackm Checksum functions Support 4
J TCC Out of memory with aliases and functions Support 5
Peter Bratton Disappearing functions Support 1
A I dont see anything in the alias/functions/batchvariables tabs in IDE Support 13
dcantor Comments and suggestions on functions for binary buffers Support 4

Similar threads