Loading Scripts with an :Include

Writing and using Classes in Dyalog APL

Loading Scripts with an :Include

Postby ray on Mon Jan 04, 2016 3:02 pm

For reasons that are "Off Topic" here, I am not a fan of Scripts in Dyalog APL.

When defining a "Class", to get around my dislike of scripts, I define all my methods (functions and operators) in a classic namespace, and then put an ":Include" statement naming the Namespace that holds the methods, in the script.

This works well, the class script contains the class statement, the include statement(s), and the Field declarations, but no methods.

However, when it comes to using LOADing the script into a new workspace, the "]Load" fails with a DOMAIN ERROR.

It appears that the script cannot be incorporated into the workspace if the script contains an ":Include" statement, if the namespace named in the ":Include" does not already exist in the current workspace.


So before I can load a class that contains one or more ":Include"s, I have to know in advance what namespaces have been ":Include"d in the script. But because the script in not loaded in the workspace I cannot open the class up in the APL editor to see which namespaces are missing causing the DOMAIN ERROR.

I note that the same type of problems occurs if the class contains a reference to a base class.


A user command that allows one to "View" a class script without loading it, would be helpful here.
Ray Cannon
Please excuse any smelling pisstakes.
User avatar
ray
 
Posts: 167
Joined: Wed Feb 24, 2010 12:24 am
Location: Blackwater, Camberley. UK

Re: Loading Scripts with an :Include

Postby DanB|Dyalog on Mon Jan 04, 2016 9:20 pm

Ray, do you know where the namespaces that you want to include are?
If you do, ]load allows you to include them simply by adding a comment, usually on the same line as your :include statement, that starts with "⍝∇:require ", followed by the path to the namespace, e.g.
Code: Select all
   :include listsUtils     ⍝∇:require \project\lib\listsUtils

If your included namespace is in the same location as your class you can write
Code: Select all
   :include listsUtils     ⍝∇:require =\listsUtils
where '=' means "same location as this script".
Of course this means that your namespace should be ]saved on file and that means usually in scripted form.
/Dan
DanB|Dyalog
 

Re: Loading Scripts with an :Include

Postby Phil Last on Tue Jan 05, 2016 11:27 am

Prior to doing
      ]load path\name.dyalog
you can do
      ]file.edit path\name.dyalog
which brings it in, uses the function editor to view or edit it, writes it back if you change it and throws it away.
User avatar
Phil Last
 
Posts: 549
Joined: Thu Jun 18, 2009 6:29 pm

Re: Loading Scripts with an :Include

Postby ray on Wed Jan 06, 2016 11:36 am

Dan, Phil, Thank you both for your replies.

I was unaware of the ":requires" syntax, which does the trick when using :Include with scripped namespaces.

"Of course this means that your namespace should be ]saved on file and that means usually in scripted form."

However, the reason I am using the :Include was I do not want/have my function/methods in a script, but in a classic namespace saved in a workspace.

The "]file.edit path\name.dyalog" does allow me to both see the contents of the Script from within APL and gives me the option to comment out the offending :Include so I can at least load the class (minus methods) into the workspace.

Thanks once again for your suggestions.
Ray Cannon
Please excuse any smelling pisstakes.
User avatar
ray
 
Posts: 167
Joined: Wed Feb 24, 2010 12:24 am
Location: Blackwater, Camberley. UK

Re: Loading Scripts with an :Include

Postby Phil Last on Wed Jan 06, 2016 9:01 pm

Another thought Ray.

With ]file.edit you're looking at an image of the file.
Rather than:
    Changing it.
    Having the changes written back.
    ]LOADing it again
Why not:
    Select all and copy.
    Quit the edit.
    )ed ○ (or ⍟) whatever
    Paste.
    Edit the script in the ws without the danger of overwriting the original without testing it first.
User avatar
Phil Last
 
Posts: 549
Joined: Thu Jun 18, 2009 6:29 pm


Return to Object Oriented Programming

Who is online

Users browsing this forum: No registered users and 1 guest