cancel
Showing results for 
Search instead for 
Did you mean: 

Function Call Juxtaposition - Language Lawyer Question

User
Not applicable
Hi,
Here is another language lawyerly question:
Usual function call syntax is like : f[(p1;p2;p3)]

Then how does the interpreter know the recognize the following as a function call 

 f p1 p2 p3  ?

Then if you were to think about function in bigger complex expressions, the question becomes even more interesting ?

Is there an general way to figure these correct syntax / order of evaluation questions out ?
4 REPLIES 4

erik_friis
New Contributor
The expression p1 p2 p3 is called a strand (vector notation in APL2) and it does not work in q.  The only place vector notation (in the APL sense) works in q is in denoting simple lists of integers/reals.

f (p1;p2;p3) is the juxtaposition and is picked up by the parser.

josepablocam
New Contributor
The nice thing with q is that there is no guessing about order of evaluation. It's right to left and that's that. So in a case like f[a1;a2.....an] an would evaluate first, then a_n-1, and so forth until a1. A quick experiment shows this clearly

q){x+y}[0N!1;0N!2]

2

1

3


Also, not sure if you intended to call f[(p1;p2;p3)], or f[p1;p2;p3]. Note that those 2 are different, the first one takes 1 parameter, while the second takes 3. And as @Erik Friis mentioned your f p1 p2 p3 won't work.


On Tuesday, July 7, 2015 at 9:22:51 PM UTC-7, analyst wrote:
Hi,
Here is another language lawyerly question:
Usual function call syntax is like : f[(p1;p2;p3)]

Then how does the interpreter know the recognize the following as a function call 

 f p1 p2 p3  ?

Then if you were to think about function in bigger complex expressions, the question becomes even more interesting ?

Is there an general way to figure these correct syntax / order of evaluation questions out ?

Well not everything is strictly right to left.  Consider the two following expressions:

a[1][2][3]

This repeated item indexing expression is evaluated as:
((a[1]))[2])[3]

And expressions with multiple adverbs:

x @'' y

is evaluated as:

x (@')' y

But for the most part as José says the right to left order or evaluation is quite straightforward and one of the strong suits of q, k, j, and APL.

Most things are evaluated from right to left, but not everything as Eric mentioned 🙂
Another example is evaluation of where clause in select statement: right to left evaluation inside each where clause, but left to right per comma separated condition

In analyst example  f p1 p2 p3, it doesn't work just because 1 2 3 is being treated as a single parameter, it will work with dot operator applied: f . p1 p2 p3

Charles