2

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?

Adám
  • 6,573
  • 20
  • 37
Sohang Chopra
  • 46
  • 2
  • 4

2 Answers2

4

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.

Morten Kromberg
  • 643
  • 5
  • 5
  • Thanks! Now I have saved one function in a file, like you said (using ```]save```). But how do I actually load the function in Dyalog REPL? I tried ```]load ``` but that gave error ```could not fix```. – Sohang Chopra May 29 '21 at 18:34
  • I was able to ]save and ]load both the function and the variable using Morten's instructions. In Windows version. – Paul Mansour May 29 '21 at 22:15
2

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.

Paul Mansour
  • 1,436
  • 9
  • 11
  • Thanks, that's useful! And yes, I considered writing the function using a vector ```+/summul 3 5 15``` - but this will add all values, whereas I need to sum first two but subtract last elenent. Any hints for doing that? – Sohang Chopra May 29 '21 at 18:44
  • A few hints: 1) note order of operations in APL for your current solution. 2) To explore more idiomatic APL solutions examine outer product ("jot dot") – Paul Mansour May 29 '21 at 22:12
  • That outer product looks interesting! I'll check it out for sure! – Sohang Chopra May 31 '21 at 08:27