Guides/Distributing J Code

From J Wiki
Jump to navigation Jump to search

This page is mostly about distributing open source code to other developers in the community.

If you'd like to distribute J applications to end users, see: Guides/J8_Standalone


How do I distribute my J code to other J users?

You can create a personal addon using a github repository. For example:

To install this addon from J:

   install'github:cdburke/testjal'
   load'~addons/cdburke/testjal/test.ijs'

What is the structure of manifest.ijs ?

This is documented at Addons/Developers_Guide

How can I allow loading without the explicit ~/addons/ and .ijs extensions?

Just add a .ijs file to the manifest that has the same name as the last part of the folder name.

The actual work is done by getscripts_j_, which is called by load:

      getscripts_j_'namespace/package'
   ┌──────────────────────────────────────────────────────────┐
   │c:/program files/j902/addons/namespace/package/package.ijs│
   └──────────────────────────────────────────────────────────┘

How do I perform a 'relative import' when my project is broken into multiple files?

You just load the full path: '~addons/repo/package/script.ijs'

The trick comes when you want the same code to work from a different path while you are developing the package.

One option is to just keep your local copy of the repository directly under the ~addons folder (type jpath'~addons' to see where it is.)

If you'd like to have your code dynamically determine the local directory, you could use this trick:

   relpath =: {{ (fpath_j_ jpath>(4!:4<'relpath'){4!:3),'/',y }}
   load relpath 'whatever.ijs'

(adapted from https://github.com/zerowords/tgsjo/blob/master/tgsjo.ijs )