Page 1 of 1

Stupid question - entering multi-line dfns...

Posted: Fri May 15, 2015 9:50 pm
by jwt
I'm trying to figure out how to enter a multi-line dfn, such as:

Code: Select all

fact←{    ⍝ Factorial ⍵.
     ⍵≤1: 1      ⍝ Small ⍵, finished,
     ⍵×∇ ⍵-1     ⍝ Otherwise recurse.
      }


If I try to type it directly into the session it fails on the first line with a syntax error. How can I do this?

Thanks in advance.

Re: Stupid question - entering multi-line dfns...

Posted: Sat May 16, 2015 11:37 am
by PGilbert
Hello, on this link it is explained how to paste a multiline DFN into the session.

Also you can type the name of an empty DFN like this:
      fact←{}

hit return and than double-click on 'fact', that should popup the editor. In the editor you are able to write multi-line DFN.

Re: Stupid question - entering multi-line dfns...

Posted: Sat May 16, 2015 12:29 pm
by JohnS|Dyalog
FYI: We have discussed allowing entry of multi-line dfns and control structures directly into the session but there is no implementation schedule for this at present. In the meantime, there's a model for a suggested behaviour at http://dfns.dyalog.com/n_din.htm and a User Command based on this model:

      ]dinput
····fact←{
········⍵=1:1
········⍵×∇⍵-1
····}

Re: Stupid question - entering multi-line dfns...

Posted: Mon May 18, 2015 8:24 am
by AndyS|Dyalog
You can do slightly better than Pierre's method of creating a new dfn (or indeed, tradfn): simply type the name of the function that you want to create, and hit <EDit> or double-click on the name. Then start typing:
fact←{ ..

If you want to create a new function/operator, or a new scripted namespace/class/interface you just need to open the editor .. and once in the editor, the name of the object that you save is the name that appears in the header, not the name that you used when opening the editor.

I frequently generate a new class by typing
      )ed ○cl

and then worrying about what the real name is that I want to use.

Of course, this leaves the cursor on an altered line in the session, which you can either use to execute or trace the new function, or hit <QuiT> (Shift-Escape) to kill that line.

Note that I've mentioned two groups of objects .. (functions and operators), and (scripted namespaces, classes and interfaces); due to the the very different natures of these two groups you cannot convert from an object of one group to an object of the other group in the editor.