Function Editing: Difference between revisions

From NARS2000
Jump to navigationJump to search
(New page: * To invoke the function editor, type <apll>∇</apll> by itself, or <apll>∇</apll> followed by a name, or <apll>)EDIT</apll> by itself, or <apll>)EDIT</apll> followed by a name, or doub...)
 
No edit summary
Line 1: Line 1:
* To invoke the function editor, type <apll>∇</apll> by itself, or <apll>∇</apll> followed by a name, or <apll>)EDIT</apll> by itself, or <apll>)EDIT</apll> followed by a name, or double-right-click on a function name in the session manager or function editor windows.
* To invoke the function editor, use one of the following methods:
* The function editor supports a multilevel Undo.  That is, pressing Ctrl-Z reverts back to the previous text.
** type <apll>∇</apll> by itself, or
** type <apll>∇</apll> followed by a name, or
** type <apll>)EDIT</apll> by itself, 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.
* 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.
* 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'''
** To Save & Exit a function, press Ctrl-E;
** To Save & Exit a function, press '''Ctrl-E'''
** 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 but not logical line, press '''Shift-Enter'''; if the cursor is in the middle of a line, it continues the line onto the next physical line at that point.  The continued line is identified by a '''Line Continuation''' marker (by default, '<span style="color:blue;">➥</span>' — 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 &mdash; the remaining physical lines in the block of continued lines are unnumbered.
 
<p>For example,</p>
 
<apll>[0]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&ensp;Z←L f R;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue;">➥</span>a b c d e ⍝ Locals<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue;">➥</span>f g h i j<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue;">➥</span>k l m n o ⍝ More locals<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue;">➥</span>p q r s t<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue;">➥</span>u v w x y z<br />
[1]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&ensp;Z←<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue;">➥</span>L ⍝ Left arg<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue;">➥</span>+ ⍝ Function<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue;">➥</span>R ⍝ Right arg<br />
</apll>
 
<p>This example also shows the ability to split a long function header line into several more manageable lines with comments on any of the continued lines.</p>
 
<p>If the function being edited is an Anonymous Function/Operator (AFO), then the '''Enter''' key may be used to create additional logical lines in the AFO.</p>
 
<p>For example,</p>
 
<apll>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h←{s←(+/⍵)÷2 ⋄ √×/s-0,⍵}</apll>
 
<p>Then editing this function via <apll>∇h</apll> displays a function editor window containing</p>
 
<apll>[0]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&ensp;h<br />
[1]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&ensp;s←(+/⍵)÷2 ⋄ √×/s-0,⍵<br />
</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>
 
<apll>[0]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&ensp;h<br />
[1]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&ensp;s←(+/⍵)÷2<br />
[2]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&ensp;√×/s-0,⍵ ⍝ Heron's formula for triangle area<br />
</apll>
 
<p>Note that when editing an AFO in this way, the function header line may not be changed.</p>
 
<p>Moreover, this method of editing an AFO also allows you to define additional entry points such as for an identity, prototype, or multiset function via the system labels <apll>⎕ID</apll>, <apll>⎕PRO</apll>, <apll>⎕MS</apll>, respectively.</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]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&ensp;h<br />
[1]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&ensp;s←(+/⍵)÷2<br />
[2]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&ensp;√×/s-0,⍵ ⍝ Heron's formula for triangle area<br />
[3]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&ensp;⎕ID:0<br />
</apll>
 
<p>which allows the function to be used where an identity function is required such as</p>
 
<apll>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h/⍬<br />
0<br />
</apll>

Revision as of 15:20, 7 July 2016

  • 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 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.
  • 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 continues the line onto the next physical line at that point. 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;
       a b c d e ⍝ Locals
       f g h i j
       k l m n o ⍝ More locals
       p q r s t
       u v w x y z
[1]      Z←
       L ⍝ Left arg
       + ⍝ Function
       R ⍝ Right arg

This example also shows the ability to split a long function header line into several more manageable lines with comments on any of the continued lines.

If the function being edited is an Anonymous Function/Operator (AFO), then the Enter key may be used to create additional logical lines in the AFO.

For example,

      h←{s←(+/⍵)÷2 ⋄ √×/s-0,⍵}

Then editing this function via ∇h displays 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

Note that when editing an AFO in this way, the function header line may not be changed.

Moreover, this method of editing an AFO 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.

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