Dyalog User Commands

Overview
User commands are useful for the Dyalog APL developer. Dyalog comes with a rich set of user commands, but independent parties also develop and maintain user commands. This article discusses how and where to install third-party user commands, and how to load them into.

This article assumes that you are familiar with the concept of Dyalog user commands, and that you know what a user command script is, and what specific features and properties it has. If you are not familiar with these topics this article is not for you: study Dyalog's "User Commands User Guide" first.

Dyalog installs its own set of user commands into. Installing third-party user commands into this folder has advantages and disadvantages.

Pro:


 * The user commands cannot be changed by an ordinary user (admin rights are required for that)
 * Every version of Dyalog has its own set of user commands

But what some may consider an advantage can also be viewed as a disadvantage. Installing it into a different place, the folder  (we discuss in a second where that folder lives), has some advantages:


 * The user has "write" permission to that folder, so updating is easy
 * Anything installed into this folder will be available in all installed versions of Dyalog APL

Note that every user has their own folder. Again this might be considered an advantage or a disadvantage.

Like the  folder,   is scanned for user command scripts at startup time.

Where does the folder MyUCMDs/ live?
The answer to this question depends on the operating system used.


 * Under Windows it's usually
 * Under Linux and Mac OS it is

Note that   is created by the Dyalog APL installer under Windows but it won't exist under Linux and Mac OS in versions before 19.0, so you need to create the folder yourself on non-Windows platforms.

If you have Tatin installed, or you are using version 19.0 or later (those come with Tatin automatically) then you can call this Tatin API function:

Availability of user commands
Once a user command script is moved into a  folder (or a sub-folder of it) the user command will be available from any version of APL.

And that could be the end of the story in case the user command you want to install is relatively simple, so all the code can go into the script. It's a different story when the user command relies on, say, a large set of code files that need to be loaded into  in order to execute the user command.

Now of course the user command script could check whether the code is already available in  and if not do the loading, and that would work just fine.

User commands with an API
However, these days it is becoming increasingly popular to add an API to a user command.

For example, the Dyalog APL project manager Cider comes with a rich set of user commands:

But Cider also offers an API (public interface):

If you want to use any of these API functions without the need of first calling any of the Cider user commands (that would allow the user command script to load the code into ), then you have to make sure that the code is loaded by other means, ideally at a very early stage: as part of the instantiating process.

This brings us to the real topic of this article: how to achieve that!

setup.dyalog in MyUCMDs/
We are going to introduce a script  into the folder. We are doing this because when Dyalog finds such a script then it will check whether it has a function. If so then this function will be executed.

Notes:


 * The name of the script must be lowercase because otherwise it won't be found on non-Windows platforms
 * The script can be a class or a namespace
 * The function  must accept a right argument. In our case, the right argument will be an   which stands for


 * The function  must return a result. The result will be ignored by the caller

There is no setup.dyalog yet
Create one that looks like this:

Note that this also checks the version of Dyalog APL and whether it's "Classic" or not. Amend this to your needs.

If your user command is not a Tatin package then this will do.

There is already a setup.dyalog
Copy the functions,   and   from above into your own   script and then make sure that   is called from your   function.

This makes sure that the API of your user command is available right after instantiating Dyalog APL.

User commands that are Tatin packages
Since version 0.86. 0 a Tatin package can be marked as a user command: by specifying the path to a user command script with a project.

Example:

With this line in the file  such a  package can be installed and loaded with Tatin:

Notes:


 * There is no name specified after  in the second argument of  : this makes the function use the name of the package for the folder to be created in , here


 * will look for a folder  in the   folder. If there is one, and it contains a file , then the package will be loaded into.


 * Usually  loads packages into   in case no second argument is specified, but because the folder was specified as an alias  the function knows that this is about a user command, and therefore the default target for the load operation is   rather than.


 * The user command script  is moved to the top of the folder hosting the user command, here

Loading all such user commands
If you want to make sure that all user commands that are Tatin packages are loaded into  at an early stage add this to your   script and make sure that it is called by your   function:

Note that it uses stuff from Tatin, so it works only with Tatin being available in, but since you are about to load Tatin packages that must be the case anyway.