Still strugling

Learning APL or new to Dyalog? Ask "silly" questions here, without fear...

Still strugling

Postby hbarkhof on Tue Sep 24, 2019 9:50 am

5⌈2 + 8⌈14 gives 16
but
2 + 8⌈14 gives also 16
That first 5 does not do anything ?

but 5⌈2 gives 5 ??
So I would expect 5 + 14 gives 19
----------------------------------------------
Same confusing thing :

4×2 5+3 gives 20 32
Simply don't see how to come to this.
Feeling very dumb. Sorry.

-----------------------------------------------
Ah , the first I got (I think)
first 8⌈14 = 14. Then 2 + 14 = 16. then 5⌈16 = 16 !! Correct ?

----------------------------------------------
The second one (4×2 5+3) I can only solve when I get rid of the "right to left" rule !
2 5+3 = 5 8. thus first 2+3 then 5+3 ?? thus not 5+3 first ? 4× 5 8 = 20 32
hbarkhof
 
Posts: 44
Joined: Mon Apr 09, 2018 8:37 am

Re: Still strugling

Postby paulmansour on Tue Sep 24, 2019 1:16 pm

Yes, you got the first one.

Regarding the second one, the 2 and the 5 bind together first, to form a 2-element vector. This is called strand notation, and it takes precedence over function application (I think that is the right terminology, but I will be corrected soon enough below if not). Treat this as one thing, and then use the right to left rule - so the first thing that happens is 2 5+3 which yields the two element vector 5 8.
paulmansour
 
Posts: 431
Joined: Fri Oct 03, 2008 4:14 pm

Re: Still strugling

Postby petermsiegel on Tue Sep 24, 2019 9:41 pm

Try putting parens around until you get the hang of it. It's not crazy, just different. Here are the strand (vector) notation rules from the Programmer's Guide:

A series of two or more adjacent expressions results in a vector whose elements are the enclosed arrays resulting from each expression. This is known as VECTOR (or STRAND) NOTATION. Each expression in the series may consist of one of the following:
a. a single numeric value;
b. single character, within a pair of quotes;
c. more than one character, within a pair of quotes;
d. the name of a variable;
e. the evaluated input symbol ⎕;
f. the quote-quad symbol ⍞;
g. the name of a niladic, defined function yielding a result;
h. any other APL expression which yields a result, within parentheses.

The tricky case might be when using variable names (whether on their own or mixed with constants), as in this case:
Code: Select all
      A B C D E F←1 2 3 4 5 6
      A B C + D E F
5 7 9
      (A B C) + (D E F)
5 7 9
      A B (C + D) E F
1 2 7 5 6
petermsiegel
 
Posts: 159
Joined: Thu Nov 11, 2010 11:04 pm

Re: Still strugling

Postby Veli-Matti on Wed Sep 25, 2019 5:45 am

Hi,
perhaps the easiest way to grasp this is to use parentheses (from right to left), e.g.
      5⌈(2+(8⌈14))
16
5⌈(2+ 8⌈14 )
16
5⌈ 2+ 8⌈14
16


Remember that the vector binding is stronger than function binding, thus
      4×((2 5)+3)
20 32
4× (2 5)+3
20 32
4× 2 5 +3
20 32


And last: don't ever use multiple assignment without parentheses (avoiding problems, e.g understanding the code afterwards), that's an unnecessary and irritating anomaly. The expression
      Foo Goo Hoo←...

may be interpreted as function Foo with two arguments set at once, or assigning three variables, or assigning the right argument for function Goo, or..
This becomes more hairy with namespaces, with []PATH *sigh*.

But writing
      (Foo Goo Hoo)←...


is safe, and clear, and logical.

-wm
Veli-Matti
 
Posts: 94
Joined: Sat Nov 28, 2009 3:12 pm

Re: Still strugling

Postby hbarkhof on Wed Sep 25, 2019 11:04 am

Thanks a lot , Gents. I think I got it. Very good tip to use parentheses !
hbarkhof
 
Posts: 44
Joined: Mon Apr 09, 2018 8:37 am


Return to New to Dyalog?

Who is online

Users browsing this forum: No registered users and 1 guest