Saving a new namespace

General APL language issues

Saving a new namespace

Postby augustk on Thu Feb 14, 2019 9:12 am

Currently, when I want to create a new namespace Foo stored in a text file, I create a textfile named Foo.apl outside of the Dyalog session with the content

Code: Select all
:Namespace Foo
:EndNamespace

I then load the namespace into Dyalog with

Code: Select all
⎕FIX 'file://Foo.apl'

Alternatively, I can create the namespace with

Code: Select all
⎕FIX ':Namespace Foo' ':EndNamespace'

Which command do I need to invoke in order to create Foo.apl with new namespace?
augustk
 
Posts: 27
Joined: Tue Feb 05, 2019 11:54 am

Re: Saving a new namespace

Postby Adam|Dyalog on Sun Feb 17, 2019 8:16 am

The following should work:
      'Foo.apl'{⎕FIX'file://',⍺⊣⍺⎕NPUT⍨⊂⍵}':Namespace Foo' ':EndNamespace'
It shyly returns a reference to the created namespace.

Note that the following may seem to have the same effect, but it will not associate the file with the namespace, so when you use the editor to make changes, they will not be reflected in the file. Similarly, any changes made to the file will not cause the editor to notify you:
      'Foo.apl'{⎕FIX⍵⊣⍺⎕NPUT⍨⊂⍵}':Namespace Foo' ':EndNamespace'


Also note that for safety, these will not overwrite any existing file (even if the file already contains a namespace Foo), but you can force overwriting by inserting a 1 to the immediate left of ⎕NPUT, e.g.
      'Foo.apl'{⎕FIX'file://',⍺⊣⍺1⎕NPUT⍨⊂⍵}':Namespace Foo' ':EndNamespace'
User avatar
Adam|Dyalog
 
Posts: 135
Joined: Thu Jun 25, 2015 1:13 pm

Re: Saving a new namespace

Postby augustk on Mon Feb 18, 2019 9:15 am

Adam|Dyalog wrote:The following should work:
      'Foo.apl'{⎕FIX'file://',⍺⊣⍺⎕NPUT⍨⊂⍵}':Namespace Foo' ':EndNamespace'

Thanks for the solution. However, compared to the code above it seems more straightforward to create the new file outside of the Dyalog session.
augustk
 
Posts: 27
Joined: Tue Feb 05, 2019 11:54 am

Re: Saving a new namespace

Postby Adam|Dyalog on Mon Feb 18, 2019 10:09 am

This was how to do it under program control.

Using the Dyalog IDE on Windows, here is a much nicer way to do it:
      )ed ⍟Foo
This will create a skeleton :Namespace Foo for you to populate. Then from the editor's File menu, select Save As… and type the desired file name. Now when you close the editor, the new namespace will both be fixed in the workspace and associated with the created file.

Note: The ⍟ indicates to )ed that a new namespace is to be created. The options are:
∇ function or operator
→ simple character vector
∊ vector of character vectors
- character matrix
⍟ Namespace script
○ Class script
∘ Interface
User avatar
Adam|Dyalog
 
Posts: 135
Joined: Thu Jun 25, 2015 1:13 pm

Re: Saving a new namespace

Postby augustk on Wed Feb 20, 2019 4:09 pm

Adam|Dyalog wrote:Using the Dyalog IDE on Windows, here is a much nicer way to do it:
      )ed ⍟Foo
This will create a skeleton :Namespace Foo for you to populate. Then from the editor's File menu, select Save As… and type the desired file name. Now when you close the editor, the new namespace will both be fixed in the workspace and associated with the created file.

Excellent! When using Save As… , how does the application know that I want to save the newly created namespace (as a text file) and not the Dyalog session? Suppose I have created two unsaved namespaces with )ed.
augustk
 
Posts: 27
Joined: Tue Feb 05, 2019 11:54 am

Re: Saving a new namespace

Postby Adam|Dyalog on Wed Feb 20, 2019 6:49 pm

I'm not sure what you mean by "the Dyalog session". The editor never saves the workspace (#) or the session (⎕SE). Once you do "Save As..." (and have made changes to the workspace), the editor will keep the file synced. The items in the editor menu bar always relate to the currently focused item.
User avatar
Adam|Dyalog
 
Posts: 135
Joined: Thu Jun 25, 2015 1:13 pm

Re: Saving a new namespace

Postby augustk on Thu Feb 21, 2019 8:38 am

Adam|Dyalog wrote:The items in the editor menu bar always relate to the currently focused item.

Ah, of course. I forgot that the menubar of a docked editor window changes when the editor gets focus.
augustk
 
Posts: 27
Joined: Tue Feb 05, 2019 11:54 am


Return to Language

Who is online

Users browsing this forum: Bing [Bot] and 1 guest