Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Rich H.J for C programmers.2006.pdf
Скачиваний:
18
Добавлен:
23.08.2013
Размер:
1.79 Mб
Скачать

load 'system\packages\misc\jforc.ijs'

load reads lines from the script and executes them. These lines will normally be all the verb and noun definitions your application needs, possibly including load commands for other scripts. A script may end with a line executing one of the verbs it defined, thereby launching the application; or, it may end after defining names, leaving you in control at the keyboard to type sentences for J to execute.

Note: Names defined by private assignment (using =.) when a script is loaded are not available outside the script. If you want to define names for use elsewhere, make sure you use =: for your assignments within a script.

If you are used to debugging with Visual C++™ or the like, you will find the environment less glitzy and more friendly. If you want to change a verb (function), you simply edit the script, using the editor of your choice (I use the built-in editor provided with J), and rerun it. The verb will be updated, but all defined nouns (objects) will be unchanged. Even if you are running a large application—yea, even if the application is in the middle of reading from an asynchronous socket—you can change the program, without recompiling, relinking, or reinitializing. If you'd like to add some debugging code while the system is running, go right ahead. This easy interaction with an executing program is one of the great benefits of programming in J.

Interrupting Execution

If a J verb is taking too long to run, signal it to stop by running the Jbreak program that is supplied as part of the J installation. Control will return to the keyboard.

Errors

When a sentence contains an error, J stops and displays the sentence along with a terse error message. Refer to the chapter on Error Messages for explanation of the error.

The Execution Window; Script Windows

When J starts it displays its execution window. The title of the execution window ends with the characters '.ijx'. The only way to have a sentence executed is to have the sentence sent to the execution window. The simplest way to do that is by typing the sentence into the execution window, as we have been doing in the examples so far.

The execution window is an edit window and a session log as well as a place to type sentences for execution. If you put the cursor on some line other than the last and press ENTER, the line you were on will be copied to the bottom of the session log as if you had typed it for execution. You can then edit the line before pressing ENTER again to execute it.

For convenience in editing, you may create other windows which will be script windows. Usually these windows will contain J scripts that you are working on, and the editor that manages the script windows is familiar with the syntax of J. You create a script window by clicking File on the Menu Bar and then selecting New ijs, Open, or Recent.

14

Sentences that you type into a script window are not automatically executed by J; you must copy them into the execution window to have them executed. You can use the script-window editor to send lines from a script to the execution window: click Run on the Menu Bar and then File, Selection, or Window as appropriate.

To run a selection of lines from a script window, be sure to use Run|Selection rather than cut-and-paste. If you paste a number of lines into the execution window, only the last one will be executed.

It is important to remember that the script windows exist only for your convenience in editing and are not used during execution. If you make a change to a script window, you need to Run that window to cause the lines in the script to be executed.

If you are debugging a script and you remove a definition from the script and Run it, the definition will not be removed from the J session. Running the script is like entering the sentences one by one from the keyboard, and not-defining the name does nothing to expunge an established definition. To remove the old definition, use

4!:55 <'expiredname' or start a fresh session of J.

Names Defined at Startup

When J starts, a number of useful names are defined. Rather than discuss them all, I will show you how they come to be defined so you can study them when you need to.

When J starts, it executes the script

J-directory\system\extras\config\profile.ijs which then executes the script J-directory\system\extras\util\boot.ijs . boot.ijs in turn executes a series of scripts in J-directory\system\main which define the starting environment. Look at these scripts to see what they define.

If you want to add your own initial definitions, do so either by adding commands at the end of profile.ijs or by creating your own startup script in

J-directory\system\extras\config\startup.ijs .

Step-By-Step Learning: Labs

The Labs are interactive demos describing various topics in J. To run the lab for printf, start a J session, on the menu bar select Studio|Labs…, then select the lab you are interested in, then press 'Run'. The lab provides explanatory text interspersed with examples executed in your J session which you are free to experiment with as you step through the lab.

I recommend that every now and again you tarry a while among the labs, running whichever ones seem interesting. Much of the description of the J system can be found only there.

15

J Documentation

The J documentation is available online. Pressing F1 brings up the Vocabulary page, from which you can quickly go to the Dictionary's description of each J primitive. At the top of each page of documentation are links to the manuals distributed with J: these are:

The Index to all documentation;

The User Manual which describes components of J that are not in the language itself, including system libraries and external interfaces;

The J Primer, an introduction to J;

J Phrases, a collection of useful fragments of J (you will need to finish this book before trying to use J Phrases);

The J Dictionary, the official definition of the language; Release Notes for all releases of J;

A description of foreign conjunctions (!:);

A description of the operands to the wd verb (Windows interface).

Getting Help

Your first step in learning J should be to sign up for the J Forum at www.jsoftware.com. A great many experienced J users monitor messages sent to the Forum and are willing to answer your questions on J, from the trivial to the profound.

16