>>  <<  Ndx  Usr  Pri  Phr  Dic  Rel  Voc  !:  wd  Help  User

Lab Sections

Sections
Sections are in two parts, either of which may be empty. The first part is the text to be displayed, ended by a line starting with ) . Lines after the ) are J sentences that are executed. If no ) line is given, the section is assumed to be text only.

For example, the following is a lab section named "Numbers":

Lab Section Numbers
The integer function (i.) generates numbers:
)
i.10           NB. first 10 numbers
i.4 3          NB. first 12 numbers in a 4 by 3 table

The lab system responds to Ctrl+A (advance) by reading the next section, displaying the text, and executing the J sentences. All display is normal output to the active jx window, and the user has complete access to the J session.

Section Keywords
Lines in the second part of a Lab Section (the J sentences to be executed) may begin with one of the keywords SCRIPT, PREPARE or SOUND.

  • SCRIPT allows you to enter a character string that will be stored in the global variable SCRIPT, in the jlab locale. For example, this can be used to build up an example script.

  • PREPARE allows you to enter sentences that will be run silently before the rest of the section is run.

  • SOUND is used to play sounds, where there is an accompanying sound file, see Lab Sounds.

    The SCRIPT and PREPARE keywords are used to delimit text or sentences to be run before the rest of the section, and must occur at the beginning of the section. Any text on the same line as the keyword is ignored. For example, you can use these facilities to define the global SCRIPT, or load required code, and check whether it is OK to continue the lab.

    A typical use of PREPARE is when your Lab creates Windows forms. To ensure that wd commands are sent to the selected form, start the code with a psel command, for example:

    PREPARE
    wd 'psel myform'
    PREPARE
    

    To prevent further execution of the section, signal an error. The utility assert_lab_ may be used for this purpose; the left argument is the message to display when a 0 occurs in the right argument.

    For example:

    Lab Section Printing
    The following prints the result:
    )
    PREPARE read in print fns ------------
    load 'print'
    load 'myutils'
    ERRORMSG=. 'Unable to load myutils',LF,LF,'Check they are installed'
    ERRORMSG assert_lab_ 3=nameclass <'myprintfn'
    PREPARE ------------------------------
    myprint RES
    
    Text Width
    When using ijt (plain text) files, the recommended text width is 61 characters, which should display on all screens with typical screen fonts. You can create wider lines, but some users may have to scroll the screen in order to read them.

    If LABWRAP is set on, text beginning at the left margin is automatically wrapped to width LABWIDTH when it is written to the J execution window. To avoid this, for example when including J code, indent text by one or more spaces.

    Ignored Lines
    The system ignores any lines beginning NB. ==.

    Files created with Lab Author have sections delimited with the line below, which has the text width used by the editor:

    NB. =========================================================


    >>  <<  Ndx  Usr  Pri  Phr  Dic  Rel  Voc  !:  wd  Help  User