How do I save Dyalog APL functions in a text file?

Viewed 348

I have the following APL Functions which I want to save in a .dyalog file:

⍝ Project Euler Solutions

 summul ← {+/⍵×⍳⌊1000÷⍵}
 euler1 ← (summul 3) + (summul 5) - (summul 15)

But when I typed this code in Dyalog APL Editor, and clicked Save and Return button, I got the error Cannot fix object without a name.

What does this error mean? What am I doing wrong?

2 Answers

The Dyalog editor is designed to edit a single item (function, operator, namespace script) at a time - it cannot be used to define two functions at once unless you embed them in a namespace. Your choices are:

Enter those two lines into the APL session, and then create two .dyalog files using:

]save summul /yourfolder/summul
]save euler1 /yourfolder/euler1

Alternatively, start the editor with )ed ⍟euler, which will create a namespace, into which you can paste those lines. Note that you will then need to refer to the functions with a prefix of the namespace, for example euler.summul.

You should also note that you only have one function there. The second line is an expression, not a function, and cannot be saved by itself in the Dyalog function editor. In addition to solutions by Morten above you could create one function that defines summul and then evaluates the expression:

eulerOne←{
     summul←{+/⍵×⍳⌊1000÷⍵}
     (summul 3)+(summul 5)-(summul 15)
 }

You will have to pass in a dummy argument to this function to execute it (a zero for example). A fun thing to do might be to rewrite the function to take the vector 3 5 15 as an argument.

Related