Session Manager Editing

From NARS2000
Revision as of 13:32, 29 June 2016 by WikiSysop (talk | contribs)
Jump to navigationJump to search

The session manager in NARS2000 allows a wide variety of techniques to perform common tasks.

  • The Session manager window consists of a mixture of input and output.
  • Input typically starts after a six space indent, output typically appears starting at the left edge.
  • Both input and output are subject to editing and re-execution.
  • The cursor may move about the screen changing text as desired.
    • If you press Enter on a line, the original text of that line is restored, the changed line is copied to a new line at the bottom of the screen buffer and executed.
    • If you press Ctrl-Enter on a line, the original text of that line is restored, the changed line is copied to a new line at the bottom of the screen buffer but is not executed — instead it may be further edited before pressing Enter and executed.
    • If you press Shift-Enter on a line, a new physical line is inserted on the screen immediately below the original line and starts with a Line Continuation marker (by default, '' — U+27A5). If Shift-Enter is pressed while the text cursor is in the middle of a line, the line is split in two at that point. To undo this action use the Backspace key at the start of the new line or the Delete key at the end of the preceding line. This action changes the number of physical lines, but not the number of logical lines.
    • The default Line Continuation marker may be changed by going to "Edit | Customize..." then selecting "User Preferences" and then "Line Continuation".
    • Multiple adjacent continued lines form a block which is treated as a single logical line.
    • If you press Enter on any line in a block, the block is copied to the bottom of the screen buffer and executed. If the block is already at the end of the buffer, the block is not copied; instead it is just executed.
    • If you press Ctrl-Enter on any line in a block, the block is copied to the bottom of the screen buffer but it is not executed — instead it may be further edited before pressing Enter and then executed. If the block is already at the end of the buffer, the block is not copied and not executed — in this case, Ctrl-Enter has no effect.

For example,

       f←{
⍺ ⍝ Left arg
+ ⍝ Function
⍵ ⍝ Right arg
}
       3 f 5
8
       h←{s←(+/⍵)÷2
⋄ √×/s-0,⍵ ⍝ Heron's formula for triangle area
}

The above example (starting with h←) also illustrates how to create a multi-statement anonymous function or operator (AFO) with comments, where separate physical lines form a single logical line. Note that this is different from a multi-line AFO where separate physical lines form separate logical lines — we don't support that as yet. In particular, a statement with continued lines is still a single logical line (minus the comments which are handled specially). If a subsequent continued line does not start with a statement separator, then it is a continuation of the previous statement (as in the example above starting with f←), not a new statement.

The only syntax elements that can't be continued to the next line are names and comments — splitting a name in two creates two separate names; splitting a comment in two does not create one continued comment nor does it create two separate comments. Instead use a comment symbol to start each comment on separate physical lines. To create a new statement, use the statement separator ().

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:

       (⎕CR 'ANALYZE')[1;]
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

which can be rewritten as several short lines

       (⎕CR 'ANALYZE')[1;]
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

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 heap of names.

Shortcut Keystrokes for Editing

  • Del
  • Shift-Del
  • Ctrl-Del
  • Ins
  • Shift-Ins
  • Ctrl-Ins
  • Home
  • Shift-Home
  • Ctrl-Home
  • End
  • Shift-End
  • Ctrl-End
  • Up
  • Shift-Up
  • Ctrl-Up
  • Down
  • Shift-Down
  • Ctrl-Down
  • Left
  • Shift-Left
  • Ctrl-Left
  • Right
  • Shift-Right
  • Ctrl-Right
  • PgDn
  • Shift-PgDn
  • Ctrl-PgDn
  • PgUp
  • Shift-PgUp
  • Ctrl-PgUp