Loading Scripts with an :Include
5 posts
• Page 1 of 1
Loading Scripts with an :Include
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.
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.
Please excuse any smelling pisstakes.
-
ray - Posts: 238
- Joined: Wed Feb 24, 2010 12:24 am
- Location: Blackwater, Camberley. UK
Re: Loading Scripts with an :Include
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.
If your included namespace is in the same location as your class you can write
Of course this means that your namespace should be ]saved on file and that means usually in scripted form.
/Dan
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
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
Prior to doing
]load path\name.dyalogyou can do
]file.edit path\name.dyalogwhich brings it in, uses the function editor to view or edit it, writes it back if you change it and throws it away.
-
Phil Last - Posts: 628
- Joined: Thu Jun 18, 2009 6:29 pm
- Location: Wessex
Re: Loading Scripts with an :Include
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.
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.
Please excuse any smelling pisstakes.
-
ray - Posts: 238
- Joined: Wed Feb 24, 2010 12:24 am
- Location: Blackwater, Camberley. UK
Re: Loading Scripts with an :Include
Another thought Ray.
With ]file.edit you're looking at an image of the file.
Rather than:
With ]file.edit you're looking at an image of the file.
Rather than:
- Changing it.
Having the changes written back.
]LOADing it again
- 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.
-
Phil Last - Posts: 628
- Joined: Thu Jun 18, 2009 6:29 pm
- Location: Wessex
5 posts
• Page 1 of 1
Return to Object Oriented Programming
Who is online
Users browsing this forum: No registered users and 0 guests
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group