Stupid question - entering multi-line dfns...

Learning APL or new to Dyalog? Ask "silly" questions here, without fear...
Post Reply
jwt
Posts: 1
Joined: Wed Apr 22, 2015 8:02 pm

Stupid question - entering multi-line dfns...

Post 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.
User avatar
PGilbert
Posts: 440
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

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

Post 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.
JohnS|Dyalog

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

Post 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
····}
User avatar
AndyS|Dyalog
Posts: 263
Joined: Tue May 12, 2009 6:06 pm

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

Post 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.
Post Reply