Specifications of lots of local variable in function

General APL language issues

Re: Specifications of lots of local variable in function

Postby Vince|Dyalog on Mon Jul 22, 2013 9:49 am

Hi Jay,

The "more text" triangle does not appear to work now in patched versions of Dyalog 13.2. I have logged this bug as 9757.

I'm sorry for any confusion.

What should happen is that you press the mouse button down on that "more text" triangle and a popup window appears with the whole text of that line wrapped so you can see the entire line.

Regards,

Vince
Attachments
longline.jpg
Vince|Dyalog
 
Posts: 413
Joined: Wed Oct 01, 2008 9:39 am

Re: Specifications of lots of local variable in function

Postby Dick Bowman on Mon Jul 22, 2013 4:16 pm

Throwing in my farthingsworth, I think there are two issues here (leaving aside the matter of how the editor can display long header lines)...

I made the suggestion somewhere else, and a long time ago, that some new syntax for function headers might be useful. Let's talk dirty and think of something like Cobol's declaration section. The targets of my comments (not Dyalog) suggested that such a change would be low on their list of priorities.

The second issue is that I wonder whether this is really a design warning for the original poster - that their defined functions are becoming too long and deserve splitting up and/or that their verbose naming is too verbose (although I'm not normally a fan of one-letter names). I say this because even as I enter my dotage with many years behind me I can't say that I can remember being much inconvenienced by the single-line header.

Anyway, I'll crawl back into my bunker now.
Visit http://apl.dickbowman.com to read more from Dick Bowman
User avatar
Dick Bowman
 
Posts: 235
Joined: Thu Jun 18, 2009 4:55 pm

Re: Specifications of lots of local variable in function

Postby jmosk on Mon Jul 22, 2013 6:47 pm

In defense of long names, I would have to state that meaningful names improves readability and documentation of functionality over terse meaningless names. The size of a function should not be dictated by how many local variable names one can fit into a function header. It sounds like ⎕Shadow does in fact allow multiple lines of local names to be included. So that does seem to go along with the suggestion of a header syntax change to allow multiple lines to be specified. The idea of using local names is so I don't clutter up the workspace with intermediate short term data. I prefer to keep )vars fairly clear after a function is completed.
+←--------------------------------------------------------------→
+ Jay Moskowitz
+←--------------------------------------------------------------→
+ http://www.linkedin.com/in/jay-moskowitz-5745b83
+
User avatar
jmosk
 
Posts: 69
Joined: Thu Jul 18, 2013 5:15 am

Re: Specifications of lots of local variable in function

Postby DanB|Dyalog on Mon Jul 22, 2013 8:32 pm

My version works as Vince described it: I get a long, non wrapping window, across the width of the screen.
That's the unusual bit, it should wrap.
It only stays visible while I hold the mouse down, this is the usual bit.

You are right about localizing names and not clutter your environment.
OTOH very long programs, in any language, should be broken down into more manageable, shorter, programs/functions, unless there is a compelling reason not to do so (I can't think of one nowadays).
It makes life easier.

BTW there is a difference between localizing a name in the header and using ⎕SHADOW: each copy of the fn on the stack gets a localized version of the names in the header. The same is true for ⎕SHADOW but ONLY IF THE CODE IS EXECUTED.
This can come in handy for recursive fns.
You could build a "local global" by executing the statement on the first call only, subsequent recursive calls could use that variable e.g. as a heap. Once the top fn exits there is no trace of the variable.
DanB|Dyalog
 

Re: Specifications of lots of local variable in function

Postby Vince|Dyalog on Wed Jul 24, 2013 1:09 pm

Hi Jay,

Bug 9757 is now fixed, so the more text triangle will work for you when you run an updated dyalog.exe.

Regards,

Vince
Vince|Dyalog
 
Posts: 413
Joined: Wed Oct 01, 2008 9:39 am

Re: Specifications of lots of local variable in function

Postby paulmansour on Tue Jul 30, 2013 1:00 am

I'm a little late to the party here, but I think that there is even a better solution than Phil's suggestion of using a dfn (direct function). This solution transcends the type of the function: simply create a namespace and stuff full, long, descriptive variable names in it. Thus you only have one variable to localize if you are in a traditional function, and none of course if you are in a direct function. For example:

Code: Select all
z←y Foo x;p;r
p←⎕NS ''
p.ThisReallyLongName←x
p.ThatReallyLongName←7
p.TheOtherReallyLongName←'Hello world'
r←SubFoo p
z←r


Note the added advantage of being able to pass around all the "local" variables by just passing the namespace p as is done with SubFoo on the next to last line.

I'm sure the OO folks have a fancy pattern name for this, but I call it "stuff the vars in a namespace".


My advice is, if you have more than alpha and omega, or a small handful of variables that can be named a, b and c (ok, I'll give you d and e too!), use a namespace and full descriptive names.
paulmansour
 
Posts: 420
Joined: Fri Oct 03, 2008 4:14 pm

Re: Specifications of lots of local variable in function

Postby DanB|Dyalog on Tue Jul 30, 2013 9:28 pm

A note to this technique:
you are actually passing the variables by reference, not by value;
any modification to one of them (or indeed to anything inside the namespace given as arg) will be reflected in the calling environment.
DanB|Dyalog
 

Previous

Return to Language

Who is online

Users browsing this forum: No registered users and 1 guest