Dyalog User Commands: Difference between revisions

Jump to navigation Jump to search
165 bytes added ,  20:52, 20 January 2023
m
no edit summary
mNo edit summary
mNo edit summary
Line 24: Line 24:
The answer to this question depends on the operating system used.  
The answer to this question depends on the operating system used.  


* Under Windows it's usually </syntaxhighlight>C:\Users\<username>\Documents\</syntaxhighlight>
* Under Windows it's usually <syntaxhighlight lang=apl inline>C:\Users\<username>\Documents\</syntaxhighlight>
* Under Linux and Mac OS it is <syntaxhighlight lang=apl inline>/home/<username>/</syntaxhighlight>
* Under Linux and Mac OS it is <syntaxhighlight lang=apl inline>/home/<username>/</syntaxhighlight>


Line 41: Line 41:


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.
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 </syntaxhighlight>⎕SE</syntaxhighlight> in order to execute the user command.  
It's a different story when the user command relies on, say, a large set of code files that need to be loaded into <syntaxhighlight lang=apl inline>⎕SE</syntaxhighlight> in order to execute the user command.  


Now of course the user command script could check whether the code is already available in <syntaxhighlight lang=apl inline>⎕SE</syntaxhighlight> and if not do the loading, and that would work just fine.
Now of course the user command script could check whether the code is already available in <syntaxhighlight lang=apl inline>⎕SE</syntaxhighlight> and if not do the loading, and that would work just fine.
Line 97: Line 97:
== setup.dyalog in MyUCMDs/ ==
== setup.dyalog in MyUCMDs/ ==


We are going to introduce a script </syntaxhighlight>setup.dyalog</syntaxhighlight> into the folder <syntaxhighlight lang=apl inline>MyUCMDs/</syntaxhighlight>. We are doing this because when Dyalog finds such a script then it will check whether it has a function <syntaxhighlight lang=apl inline>Setup</syntaxhighlight>. If so then this function will be executed.
We are going to introduce a script <syntaxhighlight lang=apl inline>setup.dyalog</syntaxhighlight> into the folder <syntaxhighlight lang=apl inline>MyUCMDs/</syntaxhighlight>. We are doing this because when Dyalog finds such a script then it will check whether it has a function <syntaxhighlight lang=apl inline>Setup</syntaxhighlight>. If so then this function will be executed.


Notes:
Notes:
Line 103: Line 103:
* The name of the script must be lowercase because otherwise it won't be found on non-Windows platforms
* 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 script can be a class or a namespace
* The function </syntaxhighlight>Setup</syntaxhighlight> must accept a right argument
* The function <syntaxhighlight lang=apl inline>Setup</syntaxhighlight> must accept a right argument


   In our case, the right argument will be an <syntaxhighlight lang=apl inline>i</syntaxhighlight> which stands for <syntaxhighlight lang=apl inline>init</syntaxhighlight>
   In our case, the right argument will be an <syntaxhighlight lang=apl inline>i</syntaxhighlight> which stands for <syntaxhighlight lang=apl inline>init</syntaxhighlight>
* The function </syntaxhighlight>Setup</syntaxhighlight> must return a result
* The function <syntaxhighlight lang=apl inline>Setup</syntaxhighlight> must return a result
   The result will be ignored by the caller
   The result will be ignored by the caller


Line 188: Line 188:
Notes:
Notes:


* There is no name specified after <syntaxhighlight lang=apl inline>[MyUCMDs]</syntaxhighlight> in the second argument of </syntaxhighlight>InstallPackages</syntaxhighlight>: this makes the function act on the name of the package, here <syntaxhighlight lang=apl inline>MyUserCommand</syntaxhighlight>
* There is no name specified after <syntaxhighlight lang=apl inline>[MyUCMDs]</syntaxhighlight> in the second argument of <syntaxhighlight lang=apl inline>InstallPackages</syntaxhighlight>: this makes the function act on the name of the package, here <syntaxhighlight lang=apl inline>MyUserCommand</syntaxhighlight>
* <syntaxhighlight lang=apl inline>LoadDependencies</syntaxhighlight> will look for a folder </syntaxhighlight>MyUserCommand</syntaxhighlight> in the <syntaxhighlight lang=apl inline>MyUCMDs/</syntaxhighlight> folder. If there is one, and it contains a file <syntaxhighlight lang=apl inline>apl-dependencies.txt</syntaxhighlight>, then the package will be loaded into </syntaxhighlight>⎕SE</syntaxhighlight>.
* <syntaxhighlight lang=apl inline>LoadDependencies</syntaxhighlight> will look for a folder <syntaxhighlight lang=apl inline>MyUserCommand</syntaxhighlight> in the <syntaxhighlight lang=apl inline>MyUCMDs/</syntaxhighlight> folder. If there is one, and it contains a file <syntaxhighlight lang=apl inline>apl-dependencies.txt</syntaxhighlight>, then the package will be loaded into <syntaxhighlight lang=apl inline>⎕SE</syntaxhighlight>.
* Usually <syntaxhighlight lang=apl inline>LoadDependencies</syntaxhighlight> loads packages into <syntaxhighlight lang=apl inline>#</syntaxhighlight> in case no second argument is specified, but because the folder was specified as an alias (</syntaxhighlight>[MyUCMDs]</syntaxhighlight>) the function knows that this is about a user command, and therefore the default target for the load operation is <syntaxhighlight lang=apl inline>⎕SE</syntaxhighlight> and not <syntaxhighlight lang=apl inline>#</syntaxhighlight>.
* Usually <syntaxhighlight lang=apl inline>LoadDependencies</syntaxhighlight> loads packages into <syntaxhighlight lang=apl inline>#</syntaxhighlight> in case no second argument is specified, but because the folder was specified as an alias (<syntaxhighlight lang=apl inline>[MyUCMDs]</syntaxhighlight>) the function knows that this is about a user command, and therefore the default target for the load operation is <syntaxhighlight lang=apl inline>⎕SE</syntaxhighlight> and not <syntaxhighlight lang=apl inline>#</syntaxhighlight>.
* The user command script </syntaxhighlight>MyUserCommand.dyalog</syntaxhighlight> is moved to the top of the folder hosting the user command, here <syntaxhighlight lang=apl inline>[MyUCMDs]/MyUserCommand</syntaxhighlight>
* The user command script <syntaxhighlight lang=apl inline>MyUserCommand.dyalog</syntaxhighlight> is moved to the top of the folder hosting the user command, here <syntaxhighlight lang=apl inline>[MyUCMDs]/MyUserCommand</syntaxhighlight>


=== Loading all such user commands ===
=== Loading all such user commands ===


If you want to make sure that all user commands that are Tatin packages are loaded into <syntaxhighlight lang=apl inline>⎕SE</syntaxhighlight> at an early stage add this to your </syntaxhighlight>setup.dyalog</syntaxhighlight> script and make sure that it is called by your <syntaxhighlight lang=apl inline>Setup</syntaxhighlight> function in that script:
If you want to make sure that all user commands that are Tatin packages are loaded into <syntaxhighlight lang=apl inline>⎕SE</syntaxhighlight> at an early stage add this to your <syntaxhighlight lang=apl inline>setup.dyalog</syntaxhighlight> script and make sure that it is called by your <syntaxhighlight lang=apl inline>Setup</syntaxhighlight> function in that script:


<syntaxhighlight lang=apl>
<syntaxhighlight lang=apl>

Navigation menu