How do I direct a dyapp loader to create a namespace?

SALT, SPICE, Subversion, etc...

How do I direct a dyapp loader to create a namespace?

Postby norbertjurkiewicz84 on Thu Nov 02, 2017 12:05 am

I'd like to have SALT load certain classes under a subnamespace.

The below gives an error.

Code: Select all
Target #
Load SampleApp
Load FmtBuilder_Demo_App/FmtBuilder.dyalog
Target #.H5R
Load H5APIEndPoint
Load H5Message
Load H5Resource
Run s←#.SampleApp.RunSample'' 


Code: Select all
Booting C:\Users\user\Documents\GitHub\H5RFramework\LoadProject.dyapp
Loaded: #.SampleApp
Loaded: #.FmtBuilder
** Load failed: ⎕SE.SALT.#.H5R is an invalid Target namespace
User avatar
norbertjurkiewicz84
 
Posts: 62
Joined: Mon Nov 01, 2010 7:26 pm

Re: How do I direct a dyapp loader to create a namespace?

Postby gil on Thu Nov 02, 2017 7:13 am

I can think of 2 options:
  1. Load entire folder
  2. User defined load function

The Load command in a dyapp script has been extended to allow loading of entire folders of scripts. If so, it creates a namespace structure matching the filesystems folder structure. If you organise your scripts like you want them in your workspace, this might work for you.

The dyapp file may contain a trad function definition instead of a load script. This is a relatively new extension (introduced 1-2 years ago?). This is essentially equivalent to a function triggered by ⎕LX. To load scripts in such a function you would use either ⎕FIX (which can load individual scripted functions as well as scripted spaces) or ⎕SE.SALT.Load (what is used by ]SALT.Load and the Load command in a traditional dyapp file).
gil
 
Posts: 71
Joined: Mon Feb 15, 2010 12:42 am

Re: How do I direct a dyapp loader to create a namespace?

Postby norbertjurkiewicz84 on Thu Nov 02, 2017 1:32 pm

Thanks, Gil,

I'm using V16 for this so I assume the latest version of SALT.

Any chance you have an example of loading with folder hierarchy?

The SALT 2.7 Docs don't mention it under the dyapp section.

3.4.1 .dyapp Files
Files with the .dyapp extension comprise a .dyapp script, each line of which is either a
Load instruction, a Target instruction or a Run instruction:
l Load instructions specify the full path and filename of the file to be loaded
l Target instructions change the target environment
l Run instructions specify the name of the method to run
The .dyapp script must include at least one Run command.
revision 20170703_270 8
SALT User Guide
For example, a .dyapp file could consist of the following lines:
Target #
Load study\files\ComponentFile
Load study\files\KeyedFile
Load MyApp
Run MyApp.Main
Files with the .dyapp extension can also contain a niladic or monadic tradfn;
double-clicking on these files allows bootstrap loading of a Dyalog application.
Starting a .dyapp file that has been created by the user runs that file in a clear workspace.
If the .dyapp file has been created by the Snap SALT function then it runs in a workspace
with the same name as the workspace from which it was created. For more information
on the Snap function, see Section 4.1


and all my attempts failed with the whole structure being brought into the root.

I've tried...

Code: Select all
Load *
Run s←#.SampleApp.RunSample'' 


Code: Select all
Load /*
Run s←#.SampleApp.RunSample'' 


Code: Select all
Load /SampleApp.dyalog
Load /H5R/*
Load /FmtBuilder/*
Run s←#.SampleApp.RunSample'' 


The results are always in the root

      )ns
#
)obs
FmtBuilder H5APIEndPoint H5Message H5Resource SampleApp
Attachments
2017-11-02_09-26-59.png
User avatar
norbertjurkiewicz84
 
Posts: 62
Joined: Mon Nov 01, 2010 7:26 pm

Re: How do I direct a dyapp loader to create a namespace?

Postby norbertjurkiewicz84 on Thu Nov 02, 2017 2:20 pm

I went as far as to copy all the objects into a new WS and ]snap the whole thing as a new project. ]snap created the structure I expected and now my subfolder has a new file called name.txt. name.txt has some [] variables settings.

Code: Select all
#.H5R (⎕IO ⎕ML ⎕WX ⎕CT ⎕PP)←0 3 3 1E¯14 10


The issue I'm having now is ]load ignoring anything with a folder that contains this name.txt file when doing ]load mydirctory\*
User avatar
norbertjurkiewicz84
 
Posts: 62
Joined: Mon Nov 01, 2010 7:26 pm

Re: How do I direct a dyapp loader to create a namespace?

Postby norbertjurkiewicz84 on Thu Nov 02, 2017 3:27 pm

Workaround:


I created a stub namespace that's in the root of my project. I.e. a homegrown .dyapp alternative.

It has one function with []LX set to it.

Code: Select all
LoadProject;path;files;load
 
 path←0⊃⎕NPARTS ⎕WSID
 load←{⎕SE.SALT.Load ⍵}
 load path,'SampleApp.dyalog'
 load path,'FmtBuilder\FmtBuilder.dyalog'
 #.H5R←⎕NS''
 load path,'"H5R\APIEndPoint.dyalog" -target=#.H5R'
 load path,'"H5R\HTMLMessage.dyalog" -target=#.H5R'
 load path,'"H5R\HTMLViewer.dyalog" -target=#.H5R'

 ⎕←'Done Loading Project'


It's a bit of manual work but I get the structure I want and SALT is still saving changes.
User avatar
norbertjurkiewicz84
 
Posts: 62
Joined: Mon Nov 01, 2010 7:26 pm

Re: How do I direct a dyapp loader to create a namespace?

Postby gil on Thu Nov 02, 2017 9:53 pm

Sorry Norbert, I spoke to soon. You are right, to load a folder structure you need to snap it first as that creates the meta data for traditional namespaces (the name.txt file). I didn't know that it in turn prevents you from loading the content using the wildcard approach ]load dir\*

Either way, if you do want all files to be loaded into your workspace, just create the structure in your workspace first and then snap it (as you've discovered already).

If you want to cherry pick and load specific files into specific namespaces then go with my second suggestion. Create a trad fn that builds up your app and ]save it to file with a .dyapp extension. For example:

Code: Select all
LoadApp;⎕ML;⎕IO;fix;dir
 ⎕ML←⎕IO←1
 fix←{⍺.⎕FIX'file://',⍵}
 dir←{⊃⎕NINFO⍠1⊢⍵,'/*.dyalog'}

 # fix'SampleApp.dyalog'
 'H5R'#.⎕NS''
 #.H5R fix¨dir'./H5R'

 ⎕←'Done loading'


Code: Select all
]save LoadApp .\LoadApp.dyapp
gil
 
Posts: 71
Joined: Mon Feb 15, 2010 12:42 am

Re: How do I direct a dyapp loader to create a namespace?

Postby Adam|Dyalog on Mon Nov 06, 2017 10:50 am

You can tell ]Snap to create the desired .dyapp file for you by using the -loadfn= modifier.

Try it online!
User avatar
Adam|Dyalog
 
Posts: 134
Joined: Thu Jun 25, 2015 1:13 pm


Return to Source Code Management

Who is online

Users browsing this forum: No registered users and 1 guest