Function Editing: Difference between revisions
No edit summary |
|||
(10 intermediate revisions by the same user not shown) | |||
Line 4: | Line 4: | ||
** type <apll>)EDIT</apll> by itself, or | ** type <apll>)EDIT</apll> by itself, or | ||
** type <apll>)EDIT</apll> followed by a name, or | ** type <apll>)EDIT</apll> followed by a name, or | ||
** double-right-click on a function name in the session manager or function editor windows. | ** double-right-click on a function name in the session manager or function editor windows. The button to double-click may be changed from the menu "Edit | Customize..." then selecting "User Preferences" and then "Reverse double-click" | ||
* The function editor supports a multilevel Undo. That is, pressing '''Ctrl-Z''' reverts back to the previous text. | * The function editor supports a multilevel Undo. That is, pressing '''Ctrl-Z''' reverts back to the previous text. | ||
* Each function's undo buffer is saved with the function for reuse the next time that function is edited. | ** Each function's undo buffer is saved with the function for reuse the next time that function is edited. | ||
* All function's undo buffers are saved with the workspace for reuse on the next load. | ** All function's undo buffers are saved with the workspace for reuse on the next load. | ||
* In the function header, except for the semicolon that separates the header template from the first local name, any semicolon may be replaced by one or more spaces as in <apll>[0] Z←L FOO R;⎕IO ⎕CT a b c</apll>. | |||
* While editing a function, several keystrokes are available: | * While editing a function, several keystrokes are available: | ||
** To Save a function, press '''Ctrl-S''' | ** To Save a function, press '''Ctrl-S''' | ||
Line 13: | Line 14: | ||
** To Quit without saving the function, press '''Ctrl-Q''' | ** To Quit without saving the function, press '''Ctrl-Q''' | ||
** To create a new physical and logical line, press '''Enter'''; if the cursor is in the middle of a line, it breaks the line in two at that point | ** To create a new physical and logical line, press '''Enter'''; if the cursor is in the middle of a line, it breaks the line in two at that point | ||
** To create a new physical but not logical line, press '''Shift-Enter'''; if the cursor is in the middle of a line, it | ** To create a new physical but not logical line, press '''Shift-Enter'''; if the cursor is in the middle of a line, it breaks the line at that point onto the next physical line. The continued line is identified by a '''Line Continuation''' marker (by default, '<span style="color:blue;"><apll>➥</apll></span>' — U+27A5) at the start of the line. | ||
** Multiple adjacent continued lines form a '''block''' which is treated as a single logical line. | ** Multiple adjacent continued lines form a '''block''' which is treated as a single logical line. | ||
** The default '''Line Continuation''' marker may be changed by going to "Edit | Customize..." then selecting "User Preferences" and then "Line Continuation". | ** The default '''Line Continuation''' marker may be changed by going to "Edit | Customize..." then selecting "User Preferences" and then "Line Continuation". | ||
Line 20: | Line 21: | ||
<p>For example,</p> | <p>For example,</p> | ||
<apll>[0]  Z←L f R | <apll>[0]  Z←L f R | ||
[1]  Z← | [1]  Z← | ||
<span style="color:blue;">➥</span>L ⍝ Left arg | <span style="color:blue;">➥</span>L ⍝ Left arg | ||
<span style="color:blue;">➥</span>+ ⍝ Function | <span style="color:blue;">➥</span>+ ⍝ Function | ||
<span style="color:blue;">➥</span>R ⍝ Right arg | <span style="color:blue;">➥</span>R ⍝ Right arg | ||
</apll> | </apll> | ||
<p>Another use for Line Continuations is in function headers with a large number of local variables. The following example is taken from the <apll>ANALYZE</apll> function in the <apll>2by2</apll> workspace:</p> | <p>Another use for Line Continuations is in function headers with a large number of local variables. The following example is taken from the <apll>ANALYZE</apll> function in the <apll>2by2</apll> workspace:</p> | ||
<apll>[0]  gTRACE←{bBstrNums} ANALYZE STRING;TCNL;TCNUL;LSTACK;RSTACK;CUROBJ;REDUCTIONS;OBJ;EVENT;UNK;DOP;DOPN;MOP;MOPN;IDX;F;MF;NF;A;SA;J;EOS;LP;RP;LBK;SEMI;RBK;ARBK;SRBK;LBC;RBC;SP;BSTR;SYNOBJ;RES;FFR;FR;AFR;HFR;GO;NAM;SPA;SPD;SPF;SPM;SPHY;SPNF;CS0;CS1;CSF;CSI;CSIA;CSIV;HY;MR;DR;HR;SPFR;SPMR;SPDR;SPHR;SPMN;SPDN;JD;SOS;LASTRIGHT;AFOG;AFOR;CSEF;CSFN;IO;ISPA;LNR;NNR;NR;SYNR;SYSN;VALR;NVAL;LftStkLen;RhtStkLen;⎕IO | <apll>[0]  gTRACE←{bBstrNums} ANALYZE STRING;TCNL;TCNUL;LSTACK;RSTACK;CUROBJ;REDUCTIONS;OBJ;EVENT;UNK;DOP;DOPN;MOP;MOPN;IDX;F;MF;NF;A;SA;J;EOS;LP;RP;LBK;SEMI;RBK;ARBK;SRBK;LBC;RBC;SP;BSTR;SYNOBJ;RES;FFR;FR;AFR;HFR;GO;NAM;SPA;SPD;SPF;SPM;SPHY;SPNF;CS0;CS1;CSF;CSI;CSIA;CSIV;HY;MR;DR;HR;SPFR;SPMR;SPDR;SPHR;SPMN;SPDN;JD;SOS;LASTRIGHT;AFOG;AFOR;CSEF;CSFN;IO;ISPA;LNR;NNR;NR;SYNR;SYSN;VALR;NVAL;LftStkLen;RhtStkLen;⎕IO | ||
[1] ... | [1] ... | ||
</apll> | </apll> | ||
<p>which can be rewritten using Line Continuations as several short lines</p> | <p>which can be rewritten using Line Continuations as several short lines</p> | ||
<apll>[0]  gTRACE←{bBstrNums} ANALYZE STRING; | <apll>[0]  gTRACE←{bBstrNums} ANALYZE STRING; | ||
<span style="color:blue;">➥</span>TCNL TCNUL LSTACK RSTACK CUROBJ REDUCTIONS | <span style="color:blue;">➥</span>TCNL TCNUL LSTACK RSTACK CUROBJ REDUCTIONS | ||
<span style="color:blue;">➥</span>OBJ EVENT UNK DOP DOPN MOP MOPN IDX F MF NF A SA J EOS LP RP | <span style="color:blue;">➥</span>OBJ EVENT UNK DOP DOPN MOP MOPN IDX F MF NF A SA J EOS LP RP | ||
<span style="color:blue;">➥</span>LBK SEMI RBK ARBK SRBK LBC RBC SP BSTR SYNOBJ RES FFR FR AFR | <span style="color:blue;">➥</span>LBK SEMI RBK ARBK SRBK LBC RBC SP BSTR SYNOBJ RES FFR FR AFR | ||
<span style="color:blue;">➥</span>HFR GO NAM SPA SPD SPF SPM SPHY SPNF CS0 CS1 CSF CSI CSIA CSIV | <span style="color:blue;">➥</span>HFR GO NAM SPA SPD SPF SPM SPHY SPNF CS0 CS1 CSF CSI CSIA CSIV | ||
<span style="color:blue;">➥</span>HY MR DR HR SPFR SPMR SPDR SPHR SPMN SPDN JD SOS LASTRIGHT AFOG | <span style="color:blue;">➥</span>HY MR DR HR SPFR SPMR SPDR SPHR SPMN SPDN JD SOS LASTRIGHT AFOG | ||
<span style="color:blue;">➥</span>AFOR CSEF CSFN IO ISPA LNR NNR NR SYNR SYSN VALR NVAL LftStkLen RhtStkLen ⎕IO | <span style="color:blue;">➥</span>AFOR CSEF CSFN IO ISPA LNR NNR NR SYNR SYSN VALR NVAL LftStkLen RhtStkLen ⎕IO | ||
[1] ... | [1] ... | ||
</apll> | </apll> | ||
<p>which can then be further organized into groups of related local variables along with a trailing comment on each line, as opposed to the typical practice of the function header as a disorganized unordered pile | <p>which can then be further organized into groups of related local variables along with a trailing comment on each line, as opposed to the typical practice of the function header as a disorganized unordered pile onto which names are tossed.</p> | ||
<apll>[0]  gTRACE←{bBstrNums} ANALYZE STRING; | <apll>[0]  gTRACE←{bBstrNums} ANALYZE STRING; | ||
<span style="color:blue;">➥</span>⎕IO BSTR CUROBJ EVENT LASTRIGHT OBJ REDUCTIONS RES SYNOBJ TCNL TCNUL ⍝ Local vars | <span style="color:blue;">➥</span>⎕IO BSTR CUROBJ EVENT LASTRIGHT OBJ REDUCTIONS RES SYNOBJ TCNL TCNUL ⍝ Local vars | ||
<span style="color:blue;">➥</span>LftStkLen RhtStkLen LSTACK RSTACK   ⍝ Stack vars | <span style="color:blue;">➥</span>LftStkLen RhtStkLen LSTACK RSTACK   ⍝ Stack vars | ||
<span style="color:blue;">➥</span>A AFOG AFOR AFR ARBK CS0 CS1 CSEF CSF CSFN CSI CSIA CSIV ⍝ Syntax objects | <span style="color:blue;">➥</span>A AFOG AFOR AFR ARBK CS0 CS1 CSEF CSF CSFN CSI CSIA CSIV ⍝ Syntax objects | ||
<span style="color:blue;">➥</span>DOP DOPN DR EOS F FFR FR GO HFR HR HY IDX IO ISPA J JD ⍝ Syntax objects | <span style="color:blue;">➥</span>DOP DOPN DR EOS F FFR FR GO HFR HR HY IDX IO ISPA J JD ⍝ Syntax objects | ||
<span style="color:blue;">➥</span>LBC LBK LNR LP MF MOP MOPN MR NAM NF NNR NR NVAL ⍝ Syntax objects | <span style="color:blue;">➥</span>LBC LBK LNR LP MF MOP MOPN MR NAM NF NNR NR NVAL ⍝ Syntax objects | ||
<span style="color:blue;">➥</span>RBC RBK RP SA SEMI SOS SP SPA SPD SPDN SPDR SPF SPFR SPHR ⍝ Syntax objects | <span style="color:blue;">➥</span>RBC RBK RP SA SEMI SOS SP SPA SPD SPDN SPDR SPF SPFR SPHR ⍝ Syntax objects | ||
<span style="color:blue;">➥</span>SPHY SPM SPMN SPMR SPNF SRBK SYNR SYSN UNK VALR ⍝ Syntax objects | <span style="color:blue;">➥</span>SPHY SPM SPMN SPMR SPNF SRBK SYNR SYSN UNK VALR ⍝ Syntax objects | ||
[1] ... | [1] ... | ||
</apll> | </apll> | ||
==Editing An Anonymous Function/Operator ( | ==Editing An Anonymous Function/Operator/Hyperator (AFOH)== | ||
<p>If the function being edited is an | <p>If the function being edited is an AFOH, then '''Shift-Enter''' may be used (as above) to create additional physical but not logical lines, and '''Enter''' may be used to create additional both physical and logical lines.</p> | ||
<p>For example,</p> | <p>For example, type</p> | ||
<apll> h←{s←(+/⍵)÷2 ⋄ √×/s-0,⍵}</apll> | <apll> h←{s←(+/⍵)÷2 ⋄ √×/s-0,⍵}</apll> | ||
<p>and then | <p>and then edit this function via <apll>∇h</apll> or <apll>)EDIT h</apll> or double-clicking the name <apll>h</apll> to display a function editor window containing</p> | ||
<apll>[0]  h | <apll>[0]  h | ||
[1]  s←(+/⍵)÷2 ⋄ √×/s-0,⍵ | [1]  s←(+/⍵)÷2 ⋄ √×/s-0,⍵ | ||
</apll> | </apll> | ||
<p>This function may be edited further by deleting the diamond separator and pressing '''Enter''' at that point so as to split the line in two, resulting in</p> | <p>This function may be edited further by deleting the diamond separator and pressing '''Enter''' at that point so as to split the line in two, resulting in</p> | ||
<apll>[0]  h | <apll>[0]  h | ||
[1]  s←(+/⍵)÷2 | [1]  s←(+/⍵)÷2 | ||
[2]  √×/s-0,⍵ ⍝ Heron's formula for triangle area | [2]  √×/s-0,⍵ ⍝ Heron's formula for triangle area | ||
</apll> | </apll> | ||
<p>The '''Enter''' key is used to create a '''multi-line''' | <p>The '''Enter''' key is used to create a '''multi-physical-line''' AFOH, whereas '''Shift-Enter''' creates a '''multi-logical-line''' AFOH. The two types may appear together in a single AFOH.</p> | ||
<p>Note that when editing an | <p>Note that when editing an AFOH in this way, the function header line may not be changed.</p> | ||
<p>Moreover, this method of editing an | <p>Moreover, this method of editing an AFOH also allows you to define additional entry points such as for an identity, prototype, or multiset function via the [[System_Labels|System Labels]] <apll>⎕ID</apll>, <apll>⎕PRO</apll>, <apll>⎕MS</apll>, respectively. When system labels are used, they must appear at the start of a logical line.</p> | ||
<p>For example, the above function <apll>h</apll> could be edited to include an identity function entry point as follows:</p> | <p>For example, the above function <apll>h</apll> could be edited to include an identity function entry point as follows:</p> | ||
<apll>[0]  h | <apll>[0]  h | ||
[1]  s←(+/⍵)÷2 | [1]  s←(+/⍵)÷2 | ||
[2]  √×/s-0,⍵ ⍝ Heron's formula for triangle area | [2]  √×/s-0,⍵ ⍝ Heron's formula for triangle area | ||
[3]  ⎕ID:0 | [3]  ⎕ID:0 | ||
</apll> | </apll> | ||
<p>which allows the function to be used where an identity function is required such as</p> | <p>which allows the function to be used where an identity function is required such as</p> | ||
<apll> h/⍬ | <apll> h/⍬ | ||
0 | 0 | ||
</apll> | </apll> | ||
==Drag and Move vs. Drag and Copy== | |||
In both the function and session editors, the mouse may '''Drag and Move''' or '''Drag and Copy''' a selection to another location. The former is equivalent to Cut and Paste, while the latter is equivalent to Copy and Paste, both in a single atomic operation. | |||
After selecting the text (which may span multiple lines), release the left mouse button. Then move the mouse back to any point within the selected text, press and hold the left mouse button and Move/Copy the text to its new location. Release the left mouse button at the appropriate insertion point. | |||
During the Move/Copy, the '''text caret''' shows exactly the position of the insertion point, and the '''mouse cursor''' indicates whether or not the Ctrl-key is pressed. When the left mouse button is released, the state of the Ctrl-key is significant. If it is not pressed, the operation becomes '''Drag and Move''' which both Copies and Cuts the selected text; otherwise, the operation becomes '''Drag and Copy''' which Copies the selected text (without Cutting it) — in both case the selected text is Pasted at the insertion point. The Undo key (Ctrl-Z) restores all of the Cut/Copy/Pasted text to its previous state. |
Latest revision as of 09:36, 19 March 2019
- To invoke the function editor, use one of the following methods:
- type ∇ by itself, or
- type ∇ followed by a name, or
- type )EDIT by itself, or
- type )EDIT followed by a name, or
- double-right-click on a function name in the session manager or function editor windows. The button to double-click may be changed from the menu "Edit | Customize..." then selecting "User Preferences" and then "Reverse double-click"
- The function editor supports a multilevel Undo. That is, pressing Ctrl-Z reverts back to the previous text.
- Each function's undo buffer is saved with the function for reuse the next time that function is edited.
- All function's undo buffers are saved with the workspace for reuse on the next load.
- In the function header, except for the semicolon that separates the header template from the first local name, any semicolon may be replaced by one or more spaces as in [0] Z←L FOO R;⎕IO ⎕CT a b c.
- While editing a function, several keystrokes are available:
- To Save a function, press Ctrl-S
- To Save & Exit a function, press Ctrl-E
- To Quit without saving the function, press Ctrl-Q
- To create a new physical and logical line, press Enter; if the cursor is in the middle of a line, it breaks the line in two at that point
- To create a new physical but not logical line, press Shift-Enter; if the cursor is in the middle of a line, it breaks the line at that point onto the next physical line. The continued line is identified by a Line Continuation marker (by default, '➥' — U+27A5) at the start of the line.
- Multiple adjacent continued lines form a block which is treated as a single logical line.
- The default Line Continuation marker may be changed by going to "Edit | Customize..." then selecting "User Preferences" and then "Line Continuation".
- If line numbering is enabled for this particular function, only logical lines are numbered. That is, for a logical line continued onto the next physical line, only the starting physical line is numbered — the remaining physical lines in the block of continued lines are unnumbered.
For example,
[0] Z←L f R [1] Z← ➥L ⍝ Left arg ➥+ ⍝ Function ➥R ⍝ Right arg
Another use for Line Continuations is in function headers with a large number of local variables. The following example is taken from the ANALYZE function in the 2by2 workspace:
[0] gTRACE←{bBstrNums} ANALYZE STRING;TCNL;TCNUL;LSTACK;RSTACK;CUROBJ;REDUCTIONS;OBJ;EVENT;UNK;DOP;DOPN;MOP;MOPN;IDX;F;MF;NF;A;SA;J;EOS;LP;RP;LBK;SEMI;RBK;ARBK;SRBK;LBC;RBC;SP;BSTR;SYNOBJ;RES;FFR;FR;AFR;HFR;GO;NAM;SPA;SPD;SPF;SPM;SPHY;SPNF;CS0;CS1;CSF;CSI;CSIA;CSIV;HY;MR;DR;HR;SPFR;SPMR;SPDR;SPHR;SPMN;SPDN;JD;SOS;LASTRIGHT;AFOG;AFOR;CSEF;CSFN;IO;ISPA;LNR;NNR;NR;SYNR;SYSN;VALR;NVAL;LftStkLen;RhtStkLen;⎕IO [1] ...
which can be rewritten using Line Continuations as several short lines
[0] gTRACE←{bBstrNums} ANALYZE STRING; ➥TCNL TCNUL LSTACK RSTACK CUROBJ REDUCTIONS ➥OBJ EVENT UNK DOP DOPN MOP MOPN IDX F MF NF A SA J EOS LP RP ➥LBK SEMI RBK ARBK SRBK LBC RBC SP BSTR SYNOBJ RES FFR FR AFR ➥HFR GO NAM SPA SPD SPF SPM SPHY SPNF CS0 CS1 CSF CSI CSIA CSIV ➥HY MR DR HR SPFR SPMR SPDR SPHR SPMN SPDN JD SOS LASTRIGHT AFOG ➥AFOR CSEF CSFN IO ISPA LNR NNR NR SYNR SYSN VALR NVAL LftStkLen RhtStkLen ⎕IO [1] ...
which can then be further organized into groups of related local variables along with a trailing comment on each line, as opposed to the typical practice of the function header as a disorganized unordered pile onto which names are tossed.
[0] gTRACE←{bBstrNums} ANALYZE STRING; ➥⎕IO BSTR CUROBJ EVENT LASTRIGHT OBJ REDUCTIONS RES SYNOBJ TCNL TCNUL ⍝ Local vars ➥LftStkLen RhtStkLen LSTACK RSTACK ⍝ Stack vars ➥A AFOG AFOR AFR ARBK CS0 CS1 CSEF CSF CSFN CSI CSIA CSIV ⍝ Syntax objects ➥DOP DOPN DR EOS F FFR FR GO HFR HR HY IDX IO ISPA J JD ⍝ Syntax objects ➥LBC LBK LNR LP MF MOP MOPN MR NAM NF NNR NR NVAL ⍝ Syntax objects ➥RBC RBK RP SA SEMI SOS SP SPA SPD SPDN SPDR SPF SPFR SPHR ⍝ Syntax objects ➥SPHY SPM SPMN SPMR SPNF SRBK SYNR SYSN UNK VALR ⍝ Syntax objects [1] ...
Editing An Anonymous Function/Operator/Hyperator (AFOH)
If the function being edited is an AFOH, then Shift-Enter may be used (as above) to create additional physical but not logical lines, and Enter may be used to create additional both physical and logical lines.
For example, type
h←{s←(+/⍵)÷2 ⋄ √×/s-0,⍵}
and then edit this function via ∇h or )EDIT h or double-clicking the name h to display a function editor window containing
[0] h [1] s←(+/⍵)÷2 ⋄ √×/s-0,⍵
This function may be edited further by deleting the diamond separator and pressing Enter at that point so as to split the line in two, resulting in
[0] h [1] s←(+/⍵)÷2 [2] √×/s-0,⍵ ⍝ Heron's formula for triangle area
The Enter key is used to create a multi-physical-line AFOH, whereas Shift-Enter creates a multi-logical-line AFOH. The two types may appear together in a single AFOH.
Note that when editing an AFOH in this way, the function header line may not be changed.
Moreover, this method of editing an AFOH also allows you to define additional entry points such as for an identity, prototype, or multiset function via the System Labels ⎕ID, ⎕PRO, ⎕MS, respectively. When system labels are used, they must appear at the start of a logical line.
For example, the above function h could be edited to include an identity function entry point as follows:
[0] h [1] s←(+/⍵)÷2 [2] √×/s-0,⍵ ⍝ Heron's formula for triangle area [3] ⎕ID:0
which allows the function to be used where an identity function is required such as
h/⍬ 0
Drag and Move vs. Drag and Copy
In both the function and session editors, the mouse may Drag and Move or Drag and Copy a selection to another location. The former is equivalent to Cut and Paste, while the latter is equivalent to Copy and Paste, both in a single atomic operation.
After selecting the text (which may span multiple lines), release the left mouse button. Then move the mouse back to any point within the selected text, press and hold the left mouse button and Move/Copy the text to its new location. Release the left mouse button at the appropriate insertion point.
During the Move/Copy, the text caret shows exactly the position of the insertion point, and the mouse cursor indicates whether or not the Ctrl-key is pressed. When the left mouse button is released, the state of the Ctrl-key is significant. If it is not pressed, the operation becomes Drag and Move which both Copies and Cuts the selected text; otherwise, the operation becomes Drag and Copy which Copies the selected text (without Cutting it) — in both case the selected text is Pasted at the insertion point. The Undo key (Ctrl-Z) restores all of the Cut/Copy/Pasted text to its previous state.