unsafe trains

General APL language issues

unsafe trains

Postby askom on Sun Dec 20, 2015 11:12 pm

Dear all,

Some days ago I sent to Dyalog a "bug report":
1) ==========================================
Hi Vince,

)vars
)fns
ave sigm

⎕cr¨↓⎕nl 3
y←ave data y←sigm x
y←+/data÷⍴data y←+/(x-ave)*2
y←y÷⍴x

⍝ sigm[1] must be y←+/(x-ave x)*2
sigm 9?9 ⍝ must be syntax error
5
⍝?????
1 ⎕stop 'ave'
sigm 9?9 ⍝ must be syntax error

ave[1]
data
7.389056099
⍝ where it come from???

Have a good day,
Sasha
=======================================

I received an answer:

2) =====================================
Hi Sasha,

I asked my colleagues about this.

The answer is that we introduced Function Trains starting with Dyalog 14.0.

In sigm,
y←+/(x-ave)*2
(x-ave) is a function train, and it gets the *2 as a right argument.


*2
is
7.389056099

For further details, please see our online help at help.dyalog.com : Programmer’s guide/Introduction/Function Trains.

Regards,
Vince
=============================================

Which shocked me...

3) ===========================================
Dear Vince,

I am so s-o-r-r-y:-( When I received your answer I was shocked a bit:-(
I pronounced many times what I had to answer you. So many times,
that I believed I sent you the answer, The deep check answered NO.

Excuse me, my dear friend!

Well, what I may answer. It is VERY dangerous situation for APL programmers.
I like the idea of functional trains. But here it looks really crazy!

I suggest limit function trains to _PRIMITIVE_ functions,

What do you think about? Should we start discussion on Dyalog APL forum?

Best regards,
Sasha.
========================================================

The answer is here:

4) =====================================================
Hi Sasha,

We do understand your concerns. But, we know that we would not limit function trains to primitive functions.

You can start a discussion about function trains on the Dyalog Forums if you wish, and then all of us will get some other opinions on this as well.

Regards,
Vince
=========================================================

And dear John added:
5) ======================================================
Hi Sasha,

I would welcome some discussion of this issue in the Dyalog APL forum. In particular, it makes a good argument for Morten's suggestion of distinguishing function and operator names using italic and bold type. see: http://www.dyalog.com/blog/2015/06/resp ... -for-dfns/

Then a train would have an italicised name to its right, which, with a bit of practice, should give the reader enough of a warning:

y←+/(x-ave)*2

Best regards,
John.
===================================================

So, I'm starting discussion.

I'd like to say, that I like trains-forks very much.
My favorite one is average as
(+/ ÷ ⍴)?10e5⍴0
0.5001670428

But see above fore unsafe case for defined functions.

And, please, explain me a benefits of using trains for defined function.

Thanks,
Sasha.
askom
 
Posts: 36
Joined: Fri Apr 09, 2010 7:22 pm

Re: unsafe trains

Postby Phil Last on Mon Dec 21, 2015 11:20 am

Both the forum page and digest mangle the display of your functions but I assume this fairly represents them -
      .
┌────────────────┬───────────────┐
│ y←ave data │ y←sigm x │
│ y←+/data÷⍴data │ y←+/(x-ave)*2 │
│ │ y←y÷⍴x │
└────────────────┴───────────────┘
(Actually the preview display also mangles that on my screen but to a lesser extent. Blanks seem to have random width.)

- in which case as pointed out (x-ave) can only be a train and would have been a syntax error before trains' implementation as would all possible expressions containing them. No previously valid code can be affected.

For identification purposes all different syntax classes can be distinguished by syntax colouring.

And for a benefit I suppose that in some other situation you might actually want (x-ave) to work.

I must admit that trains are sometimes difficult to identify. I started to look for a few examples of trains of defined fns. I knew I'd done it but they weren't easy to find.
      f←'⋄'∘≠∨quoted∨0<level
is a 7-train whose left tine is a derived fn. level and quoted are defined fns. The shortest I can make it without trains is
      f←{('⋄'≠⍵)∨(quoted ⍵)∨0<level ⍵}
which to my eyes is no clearer. If merely used rather than assigned we can sometimes look for a function followed by a right parenthesis which is either a train (f g h)w or a function derived from a conjunction (f op g)w but of course if we assign a name to a train as above we don't even need the parens. I have suggested that another editor display option, along with Reformat and Align Comments could introduce blanks between the tines of a train.

As usual with APL and every other language or code, computer oriented or not, it gets easier to read with experience.
User avatar
Phil Last
 
Posts: 628
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

Re: unsafe trains

Postby paulmansour on Mon Dec 21, 2015 11:40 am

When placing the results of the display function in HTML, the problem are the blanks - UCS 32. If you replace with UCS 160, everything lines up.
paulmansour
 
Posts: 420
Joined: Fri Oct 03, 2008 4:14 pm

Re: unsafe trains

Postby JohnS|Dyalog on Mon Dec 21, 2015 2:25 pm

The point I was trying to make is that, with a bit of practice, "Kromberg Koloring" should make it possible to spot the difference in the syntax of the following expressions:

    (x-vec)*2    ⍝ array left arg of dyadic *
    (x-ave)*2    ⍝ fork applied to monadic *2

If you look carefully, you can see that vec (an array) is in normal font while ave (a function) is in italics. A function at the right of a (sub-)expression indicates that the (sub-)expression as a whole reduces to a function (or operator as in: (dop fun)).

Regarding the utility of trains with non-primitive components: APL is good for implementing Domain Specific Languages (DSLs). In this scenario, a domain expert defines functions, which are "primitive" relative to the domain and so might be used in any construct, including a train.
JohnS|Dyalog
 


Return to Language

Who is online

Users browsing this forum: No registered users and 1 guest