manual:chapter5:listproc

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
manual:chapter5:listproc [2019/10/02 14:13]
jojo1973 [Group 7: Two-arguments, one-result commands]
manual:chapter5:listproc [2019/11/03 06:36] (current)
jojo1973 [Group 9: Quirky commands]
Line 19: Line 19:
 ==== Group 2: Commands that must use DOLIST to parallel process ==== ==== Group 2: Commands that must use DOLIST to parallel process ====
  
-This group of commands cannot use parallel processing directly, but can be “coerced” into it using the ''DOLIST'' command (see Using later in this appendix). This group consists of several subgroups:+This group of commands cannot use parallel processing directly, but can be “coerced” into it using the ''DOLIST'' command (see [[listproc#Using DOLIST for parallel processing]] later in this chapter). This group consists of several subgroups:
  
   * **Stack manipulation commands** A stack manipulation command cannot parallel process because the stack is manipulated as a whole and list objects are treated the same as any other object. Stack commands (such as ''DROP'') that take level 1 arguments will not accept level 1 list arguments.   * **Stack manipulation commands** A stack manipulation command cannot parallel process because the stack is manipulated as a whole and list objects are treated the same as any other object. Stack commands (such as ''DROP'') that take level 1 arguments will not accept level 1 list arguments.
   * **Commands that operate on a list as a whole.** Certain commands accept lists as arguments but treat them no differently than any other data object. They perform their function on the object as a whole without respect to its elements. For example, ''→STR'' converts the entire list object to a string rather than converting each individual element, and the ''=='' command tests the level 1 object against the level 2 object regardless of the objects’ types.   * **Commands that operate on a list as a whole.** Certain commands accept lists as arguments but treat them no differently than any other data object. They perform their function on the object as a whole without respect to its elements. For example, ''→STR'' converts the entire list object to a string rather than converting each individual element, and the ''=='' command tests the level 1 object against the level 2 object regardless of the objects’ types.
   * **List manipulation commands.** List manipulation commands will not parallel process since they operate on list arguments as lists rather than as sets of parallel data. However, a list manipulation command can be forced to parallel process lists of lists by using the ''DOLIST'' command. For example, <code>   * **List manipulation commands.** List manipulation commands will not parallel process since they operate on list arguments as lists rather than as sets of parallel data. However, a list manipulation command can be forced to parallel process lists of lists by using the ''DOLIST'' command. For example, <code>
-{ { 1 2 3 } { 4 5 6 } } +3:       { { 1 2 3 } { 4 5 6 } } 
-+2:                             
-« ΠLIST »+1:                     « ΠLIST » 
 +……………………………………………………………………………………
 DOLIST DOLIST
 </code> returns ''{ 6 120 }''. </code> returns ''{ 6 120 }''.
   * **Other commands that have list arguments.** Because a list can hold any number of objects of any type, it is commonly used to hold a variable number of parameters of various types. Some commands accept such lists, and because of this are insensitive to parallel processing, except by using ''DOLIST''.   * **Other commands that have list arguments.** Because a list can hold any number of objects of any type, it is commonly used to hold a variable number of parameters of various types. Some commands accept such lists, and because of this are insensitive to parallel processing, except by using ''DOLIST''.
   * **Index-oriented commands.** Many array commands either establish the size of an array in rows and columns or manipulate individual elements by their row and column indices. These commands expect these row and column indices to be real number pairs collected in lists. For example, <code>   * **Index-oriented commands.** Many array commands either establish the size of an array in rows and columns or manipulate individual elements by their row and column indices. These commands expect these row and column indices to be real number pairs collected in lists. For example, <code>
-{ 3 4 }+1:                       { 3 4 } 
 +……………………………………………………………………………………
 RANM RANM
 </code> will generate a random integer matrix having 3 rows and 4 columns. Since these commands can normally use lists as arguments, they cannot perform parallel processing, except by using ''DOLIST''. </code> will generate a random integer matrix having 3 rows and 4 columns. Since these commands can normally use lists as arguments, they cannot perform parallel processing, except by using ''DOLIST''.
   * **Program control commands.** Program control structures and commands do no perform parallel processing and cannot be forced to do so. However, programs containing these structures can be made to parallel process by using ''DOLIST''. For example, <code>   * **Program control commands.** Program control structures and commands do no perform parallel processing and cannot be forced to do so. However, programs containing these structures can be made to parallel process by using ''DOLIST''. For example, <code>
-{ 1 2 3 4 5 6 } +3:               { 1 2 3 4 5 6 } 
-+2:                             
-« IF  +1:                   « IF        
-    DUP 3 ≤ +                         DUP 3 ≤ 
-  THEN +                       THEN      
-    DROP +                         DROP    
-  END +                       END       
-»+                     »           
 +……………………………………………………………………………………
 DOLIST DOLIST
 </code> returns ''{ 4 5 6 }''. </code> returns ''{ 4 5 6 }''.
  
-==== Group 3: commands that sometimes work with parallel processing ====+==== Group 3: Commands that sometimes work with parallel processing ====
 FIXME FIXME
  
-==== Group 4: ADD and + ==== +==== Group 4: Commands that set modes / states ====
-FIXME +
- +
-==== Group 5: Commands that set modes / states ====+
 Commands that store values in system-specific locations so as to control certain modes and machine states can generally be used to parallel process data. The problem is that each successive parameter in the list cancels the setting established by the previous parameter. For example, <code> Commands that store values in system-specific locations so as to control certain modes and machine states can generally be used to parallel process data. The problem is that each successive parameter in the list cancels the setting established by the previous parameter. For example, <code>
-2 3 4 5 +1:                  { 16 32 48 
-FIX</code> is effectively the same as <code> +…………………………………………………………………………………… 
-5 +SETPREC</code> is effectively the same as <code> 
-FIX+1:                            48 
 +…………………………………………………………………………………… 
 +SETPREC
 </code> </code>
  
-==== Group 6: One-argument, one-result commands ====+==== Group 5: One-argument, one-result commands ====
 These commands are the easiest to use with parallel processing. Simply provide the command with a list of arguments instead of the expected single argument. Some examples: These commands are the easiest to use with parallel processing. Simply provide the command with a list of arguments instead of the expected single argument. Some examples:
  
-  * <code>{ 1 -2 3 -4 }+  * <code> 
 +1:                 { 1 -2 3 -4 } 
 +……………………………………………………………………………………
 ABS ABS
 </code> returns ''{ 1 2 3 4 }''. </code> returns ''{ 1 2 3 4 }''.
   * <code>   * <code>
-DEG +1:                { 0 30 60 90 } 
-{ 0 30 60 90 }+……………………………………………………………………………………
 SIN SIN
-</code> returns ''{ 0 .5. .866025403784. 1 }''.+</code> returns ''{ 0 .5. .866025403784. 1 }'' (assuming ''DEG'' mode).
   * <code>   * <code>
-{ 1 A 'SIN(Z)'}+1:             { 1 'A'SIN(Z)'} 
 +……………………………………………………………………………………
 INV INV
 </code> returns ''{ 1 'INV(A)' 'INV(SIN(Z))' }''. </code> returns ''{ 1 'INV(A)' 'INV(SIN(Z))' }''.
  
-==== Group 7: Two-arguments, one-result commands ====+==== Group 6: Two-arguments, one-result commands ====
 Two-argument commands can operate in parallel in any of three different ways: Two-argument commands can operate in parallel in any of three different ways:
  
Line 84: Line 89:
  
 In the first form, parallel elements are combined by the command: <code> In the first form, parallel elements are combined by the command: <code>
-{ 1 2 3 } +2:                     { 1 2 3 } 
-{ 4 5 6 }+1:                     { 4 5 6 } 
 +……………………………………………………………………………………
 % %
 </code> returns ''{ .04 .1 .18 }''. </code> returns ''{ .04 .1 .18 }''.
  
 In the second form, the level 1 object is combined with each element in the level 2 list in succession: <code> In the second form, the level 1 object is combined with each element in the level 2 list in succession: <code>
-{ 1 2 3 } +2:                     { 1 2 3 } 
-30+1:                            30 
 +……………………………………………………………………………………
 %CH %CH
 </code> returns ''{ 2900 1400 900 }''. </code> returns ''{ 2900 1400 900 }''.
  
 In the third form, the level 2 object is combined with each element of the level 1 list in succession: <code> In the third form, the level 2 object is combined with each element of the level 1 list in succession: <code>
-50 +2:                            50 
-{ 1 2 3 }+1:                     { 1 2 3 } 
 +……………………………………………………………………………………
 %T %T
 </code> returns ''{ 2 4 6 }''. </code> returns ''{ 2 4 6 }''.
  
-==== Group 8: Multiple-argument, one-result commands ====+==== Group 7: Multiple-argument, one-result commands ====
 Commands that take multiple (3, 4, or 5) arguments can perform parallel processing only if all arguments are lists. For example, ''{ 'SIN(X)' 'COS(X)' 'TAN(X)' } { X X X } { 0 0 0 } ROOT'' returns ''{ 0 90 0 }''. Notice that lists must be used even though the level 1 and level 2 lists each contain multiples of the same element. FIXME Commands that take multiple (3, 4, or 5) arguments can perform parallel processing only if all arguments are lists. For example, ''{ 'SIN(X)' 'COS(X)' 'TAN(X)' } { X X X } { 0 0 0 } ROOT'' returns ''{ 0 90 0 }''. Notice that lists must be used even though the level 1 and level 2 lists each contain multiples of the same element. FIXME
 +
 +==== Group 8: Multiple-result commands ====
 +Any command that allows parallel processing, but produces multiple results from its input data, will return its results as a single list. For example,<code>
 +2:                     { 1 2 3 }
 +1:                     { 4 5 6 }
 +……………………………………………………………………………………
 +R→C
 +</code> produces, as expected ''{ (1, 4) (2, 5) (3, 6) }'', but<code>
 +1:      { (1, 4) (2, 5) (3, 6) }
 +……………………………………………………………………………………
 +C→R
 +</code> produces ''{ 1 4 2 5 3 6 }'' rather than the more expected ''{ 1 2 3 } { 4 5 6 }''.
 +
 +The following ''UNMIX'' program will unmix the data given the number of expected result lists:<code>
 +« OVER SIZE
 +  → l n s « 
 +    1 n FOR 'j'
 +      j s FOR 'i'
 +        l i GET
 +      n STEP 
 +      s n / →LIST
 +    NEXT
 +  »
 +»
 +</code>
 +
 +Taking ''{ 1 4 2 5 3 6 }'' from above as the result of ''C→R'' (a command which should return two results),<code>
 +2:               { 1 4 2 5 3 6 }
 +1:                             2
 +……………………………………………………………………………………
 +UNMIX
 +</code> gives ''{ 1 2 3 } { 4 5 6 }''.
 +
 +==== Group 9: Quirky commands ====
 +A few commands behave uniquely with respect to parallel processing:
 +
 +  * ''DELALARM''. This command can take a list of arguments. Note, however, that deletions from early in the alarm list will change the alarm indices of the later alarm entries. Thus, if there are only three alarms, <code>
 +1:                       { 1 3 }
 +……………………………………………………………………………………
 +DELALARM
 +</code> will cause an error, whereas <code>
 +1:                       { 3 1 }
 +……………………………………………………………………………………
 +DELALARM
 +</code>will not.
 +  * ''DOERR''. This command forces an error state that causes all running programs and commands to halt. Thus even though providing the command with a list argument will cause the command to perform parallel processing, the first error state will cause the command to abort and none of the rest of the list arguments will be used.
 +  * ''USBRESTORE''. This command performs a system warmstart after installing the backup object into memory. All functions are terminated at that time. Thus, only the first backup object in a list will be restored. FIXME
 +
 +==== Using DOLIST for parallel processing ====
 +Almost any command or user program can be made to work in parallel over a list or lists of data by using the ''DOLIST'' command. Use ''DOLIST'' as follows.
 +
 +  * Level 1 must contain a command, a program object, or the name of a variable that contains a command or program object.
 +  * Level 2 must contain an argument count.
 +  * Level 3 and on are the argument lists.
 +
 +As an example, the following program takes three objects from the stack, tags them with the names ''a'', ''b'', and ''c'', and displays them one after the other in line 1 of the display.<code>
 +« → a b c «
 +    { a b c } DUP « EVAL » DOLIST
 +    SWAP « →TAG » DOLIST
 +    CLLCD 1 « 1 DISP 1 WAIT » DOLIST
 +  »
 +»
 +</code> FIXME
  • manual/chapter5/listproc.1570050790.txt.gz
  • Last modified: 2019/10/02 14:13
  • by jojo1973