Difference between revisions of "FORALL"
From ICE Enterprises
ConvertBot (talk | contribs) (performs a Midas command for a list of items or counter index) |
(No difference)
|
Latest revision as of 18:05, 27 April 2020
performs a Midas command for a list of items or counter index
<file/count> List filename or counter string
<command> Midas command to perform
FORALL performs the named command for each item in a list file or for each
increment of a count variable. If either argument is left blank, it prompts
for them.
<command> specifies the command to execute for each item, using a # everywhere
the current item value should be substituted.
If the <file/count> parameter includes an "=" sign, FORALL expects a count
string of the form:
#=START:END;INC
where START is the start count, END is the end count, and INC is an optional
increment. <command> is executed for each count in the loop progression, with
the current iteration number substituted for each instance of "#". For example,
nM>res n 0
nM>forall #=1:21;2 calc n n # +
sums all odd integers from 1 to 21. Counts and increments are not required to
be integers.
If the <file/count> parameter does NOT include an "=" sign, FORALL expects the
name of a file containing a list of strings or numbers. It loops through each
element of this file, substituting the indexed item wherever "#" is found in
<command>. Often the file will be generated by a FILES/F or MENU/F command:
nM>files/f t* ,,1
nM>forall FILES status #
will display the status of every file beginning with T.
To see the DEFAULTS of each Intrinsic or Macro:
nM>menu/f ,,, IM
nM>forall MENU syntax #
NOTE: When using FORALL within a macro, note that its arguments are treated
like arguments to operating system commands. The reason is that it is
unknown what kind of command you may be giving FORALL. Thus local result
parameter translation will only occur if you use the caret (^) to
indicate a result substitution. For example:
mymacro L:number
forall #=1:number ramp r# ! This will NOT work right
forall #=1:^number ramp r# ! This WILL work correctly
endmacro
NOTE: <command> cannot invoke GOTO or CALL. This is because FORALL is itself
a macro with it's own macro level and local results parameters. (The
labels, procedures and subroutines of the calling macro are not visible
to it.) If you need to call a procedure repeatedly within a macro use
the DO, FOREACH or WHILE commands.
Switches:
/ECHO - Shows each iteration of the command before performing it.