Guides/Folders and Projects

From J Wiki
Jump to: navigation, search

J has two related concepts, folder and project, that help you work with source files. Both are simply references to directories.

Folder

A folder is a name given to a directory. Using folder names instead of full pathnames means that names are typically much shorter, and that it is easy to share code between users with very different directory structures.

The nouns SystemFolders_j_ and UserFolders_j_ have tables of such names, for example:

   SystemFolders_j_
+-------+---------------------------------+
|addons |/home/chris/j8/addons            |
+-------+---------------------------------+
|bin    |/home/chris/j8/bin               |
+-------+---------------------------------+
|break  |/home/chris/j8/user/break        |
+-------+---------------------------------+
|config |/home/chris/dev/user/config/linux|
...


   UserFolders_j_
+----+----------------------------------------+
|Grid|/home/chris/deb/base/grid               |
+----+----------------------------------------+
|R   |/home/chris/deb/addons/stats/r          |
+----+----------------------------------------+
|Ide |/home/chris/deb/addons/gui/gtkide/source|
+----+----------------------------------------+
|Main|/home/chris/deb/base8/main              |
...

SystemFolders is initialized in the boot up process. UserFolders and additional entries for SystemFolders are given in the configuration file folders.cfg (open with menu Edit|Configure|Folders).

Most of the time, system folders and user folders are used together. The main difference is that the IDE expects J source to be stored under user folders, not under system folders. By convention, system folders have names beginning with lowercase, and user folders have names beginning with upper case.

Verb jpath references the folder tables. It converts strings with folder names preceded with ~ into their full pathname:

   jpath &> '~bin/profile.ijs';'~config/folders.cfg';'~R'
/home/chris/j8/bin/profile.ijs
/home/chris/dev/user/config/linux/folders.cfg
/home/chris/deb/addons/stats/r

Dots can be used to reference parent folders:

  jpath '~.R/base/random.ijs'
/home/chris/deb/addons/stats/base/random.ijs

Project

A project is a subdirectory of a folder that contains a file with extension .jproj with the same name as the directory. For example, if file c:/dev/mywork/grid/grid.jproj exists, then the directory c:/dev/mywork/grid is recognized as a project directory.

Project directories should be subdirectories of folders. For example, if folder name Mywork points to c:/dev/mywork, then this grid project can be referred to as ~Mywork/grid. In the IDE, the ~ prefix is usually omitted.

A project file can be empty, or may contain a simple list of files that define the project source.

Project Verbs

Verbs to work with projects are in locale jp. These include:

  • readsource_jp_ - this reads all files in a project's source and returns a character string
  • writesource_jp_ - this reads the source, and writes to file

Corresponding verbs ending in x delete all comments.

For example, the following reads all source in the project ~Main/project, decomments it, and writes to ~mywork/util/project.ijs. Typically, this command would be given in the project's build script:

writesourcex_jp_ '~Main/project';'~mywork/util/project.ijs'

Example

A simple example is in the demos/coins project (J803 or later).

Install this using Package Manager. Then in the Qt IDE, open project Demos/coins.

Note that the build script will write a script ~Demos/release/coins.ijs.

Use Ctrl-F9 to load the build script and check that the target script has been built.

Next use F9 to load the run script.

You can experiment by changing the board definition in the run script (e.g. BOARD=: 1), then press F9 to re-load the run script.

J Source

Most of the J script source uses folders and projects. To see this:

1. checkout or export the addons, base8 and public repositories from Subversion. These can go anywhere on your machine. The following examples assume they are written to ~home/svn.

2. load the Qt IDE, then select menu Edit|Configure|Folders. In the config file, add entries for:

Main ~home/svn/base8/main
Qt  ~home/svn/public/ide/qt/source
Addons ~home/svn/addons

Note that the paths can be jpaths as above, or full pathnames, as in:

Main /home/elmo/svn/base8/main

3. Close and reload JQt IDE. Ctrl-M to open the editor, and select menu Project|Open (or click the corresponding toolbar button). You should see the new folders listed in the first panel, and their projects in the second. Select a project to open it in the editor.