User:Brian Schott/Notebook
Retroactively producing script examples
While thinking about the features of Matlab and Mathematica which facilitate producing "Notebooks" to demonstrate one's work, I was reminded of several requests by J practitioners to enhance the IDE so as to accomplish similar feats. The IDE is quite rich in transferring script morsels from the ijs window to the ijx window using such keystrokes as Ctrl+R, Ctrl+E, Ctrl+W (and some Shift options). But I cannot find similar menu or keystroke facilities for transferring back from the ijx window to an ijs window.
Fortunately I found Jwiki/System/Interpreter/Requests such as "session executed lines" and "Input Log leading spaces" where valuable related suggestions and ideas have been offered.
It seems to me that a useful "Notebook" can be constructed retroactively from the inputs to an ijx window, especially if the outputs can be culled and recreated by running the sanitized inputs pasted to an ijs window.
Three alternative methods are sketched here, mostly with the purpose of generating ideas. Unfortunately both of the first two methods are flawed or need considerable work. See Ideas only comments below. The third medthod is more involved, but produces good results.
Examples
The session below is meant to demonstrate some of my ideas. Assume that the following is the final status of a very simple ijx window which the user wishes to annotate by creating a "Notebook".
Examples
The session below is meant to demonstrate some of my ideas. Assume that the following is the final status of a very simple ijx window which the user wishes to annotate by creating a "Notebook".
i. 5 0 1 2 3 4 Note 'Notebook' This line will not reproduce Too bad ) avg =: +/ % # avg _1 0 21 6.66667
Example 1
If the very first line in the next example is typed into the working ijx window, then the lines below it are produced for the example above. I believe that pasting the resulting lines into a new ijs window and then editing that ijs window before Ctrl+E'ing the result could produce a valuable Notebook. (It is somewhat disappointing that that the documentation using the handy verb Note are excluded.)
((''"_)`dlb@.(' '&-:@(3&{.)));._2 wd 'sminputlog' i. 5 Note 'Notebook' avg =: +/ % # avg _1 0 21
Example 2
Because the sminputlog result does not include any inputs that might have been the result of a Ctrl+R or similarly constructed inputs, an alternative method for producing a new ijs window may be preferred. This alternative method requires the user to first select the desired text in ijx window and copy that selection to the clipboard. Having completed the copying, the very first line in the next example yields all the inputs from the example above. In the present case the results are almost exactly the same as the initial alternative because there were no extra inputs. As implemented, this alternative also yields a blank line for each of the original inputs.
((''"_)`dlb@.(' '&-:@(3&{.)));._2 ,&LF wd 'clippaste' i. 5 Note 'Notebook' avg =: +/ % # avg _1 0 21
Example 3
This alternative can be done on a Macintosh, and likely on Windows computers, but I have only a Mac. On the Mac it requires a text editor application like TextEdit which permits discontinuous selection of text; on the Mac this is accomplished by Command-clicking the mouse (I will abbreviate as CC).
On Windows computers, discontinuous selection like CC may even be possible inside of the ijx window, but I have not found this feature on the Mac. Such a feature inside J would simplify this alternative considerably.
If all of the relevant portion of the ijx window is selected and then pasted into a TextEdit window, then in TextEdit CC can be used for a more restrictive selection of the required inputs alone. The CC process must be done carefully so that each line is copied with its newline character, so that no two lines will be combined later into a single line. Once the CC is completed, the final selection is copied into the clipboard. Then, return to the ijx window and execute the following instruction so that the result can be selected and Ctrl+E can be used to execute the example instructions. dlb;._2 ,&LF wd 'clippaste'
dlb;._2 ,&LF wd 'clippaste' i. 5 Note 'Notebook' This line will not reproduce Too bad ) avg =: +/ % # avg _1 0 21
Below is the result of Ctrl+E'ing the above. Notice that the first line contains 3 extra spaces.
i. 5 0 1 2 3 4 Note 'Notebook' This line will not reproduce Too bad ) avg =: +/ % # avg _1 0 21 6.66667
Comments
A similar approach, using Window Display was used in pcall addon test and demo scripts. It can be thought of as "instant lab".
- The scripts are session input lines, which are executed with Ctrl+Shift+W or select and Ctrl+E.
- The script is re-executed in toto every time, as new lines are edited or changed. So it might be good also to include an initial line to clear session
- It makes sense to keep such notebook in a moderate size, while larger text produces using inlining, as in pcall example.
Using session log is a great idea. I would even suggest enhancing the current Ctrl+D feature to allow making multi-item selection and clipboard copy to be used in such Window Display (Notebook) scripts.
Note is an interesting idea. But I would suggest using regular comments, because they render more naturally in Window Display. In addition it may be possible to extend the Export Script tool to produce HTML and Wiki format from it, where comments are converted to regular paragraph text.
-- Oleg Kobchenko <<DateTime(2007-02-22T06:05:19Z)>>
Ideas only
The second method will not work for any multiple-line definitions, just as the Note verb does not work in this context, unless the user is willing to prefix each non-initial and non-terminal line with three or more spaces. That seems to be an undue burden that would be difficult to replace with some automated scheme (ie, program).
The first method suffers because if any input line is a repeat of a previous line, the previous line is not kept. This is annoying because it can screw up the sequence of commands and can even eliminate crucial commands especially control words like do. and end. But also any repeated sequences entered in interactive executions.
So perhaps this whole page is best seen as only an idea generator for both users and developers.
-- Brian Schott <<DateTime>>