Wikipedia article on APL has come of age!

This is a discussion on Wikipedia article on APL has come of age! within the Functional forums in Programming Languages category; Wikipedia article on APL has come of age! http://en.wikipedia.org/wiki/APL_(programming_language ) See also: Conway's Game of Life in one line of APL By 2005 Michael Gertelman http://catpad.net/michael/apl/ btw, has anyone used apl mode in emacs? it doesn't seems to be bundled at least. Xah ∑ http://xahlee.org/ ☄...

Go Back   Application Development Forum > Programming Languages > Functional

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-19-2008, 04:51 PM
xahlee@gmail.com
Guest
 
Default Wikipedia article on APL has come of age!

Wikipedia article on APL has come of age!
http://en.wikipedia.org/wiki/APL_(programming_language)

See also:

Conway's Game of Life in one line of APL
By 2005 Michael Gertelman
http://catpad.net/michael/apl/

btw, has anyone used apl mode in emacs? it doesn't seems to be bundled
at least.

Xah
http://xahlee.org/


Reply With Quote
  #2  
Old 08-19-2008, 05:24 PM
xahlee@gmail.com
Guest
 
Default Re: Wikipedia article on APL has come of age!

according to
http://en.wikipedia.org/wiki/APL_(programming_language)

quote:
«As APL has many nonstandard primitives (functions and operators,
indicated by a single symbol or a combination of a few symbols), it
does not have function or operator precedence.»

that cant be true, since function is a broad conception that includes
any operators.

But my question is about the statement that APL doesn't have operator
precedence. As far as i know, in linear textual languages (as opposed
to spread sheets, visual langs etc), unless it uses nested functional
notation (e.g. Mathematica, lisp), i can't see how it can do without
operator precedence?

For example, in Wikipedia this code example for picking 6 random
numbers from 1 to 40:

↑6?40

certainly there's operator precedence. e.g.

(↑(6?40))
(↑(6?)40)
(↑(6(?40)))
(↑6)(?40)

etc.

So i think the Wikipedia statement “it does not have function or
operator precedence” is wrong or needs qualifications.

Xah
http://xahlee.org/



On Aug 19, 1:51*pm, "xah...@gmail.com" <xah...@gmail.com> wrote:
> Wikipedia article on APL has come of age!http://en.wikipedia.org/wiki/APL_(programming_language)
>
> See also:
>
> Conway's Game of Life in one line of APL
> By 2005 Michael Gertelmanhttp://catpad.net/michael/apl/
>
> btw, has anyone used apl mode in emacs? it doesn't seems to be bundled
> at least.
>
> * Xah
> ∑http://xahlee.org/
>
> ☄


Reply With Quote
  #3  
Old 08-19-2008, 06:09 PM
Stuart McGraw
Guest
 
Default Re: Wikipedia article on APL has come of age!

xahlee@gmail.com wrote:
> according to
> http://en.wikipedia.org/wiki/APL_(programming_language)
>
> quote:
> «As APL has many nonstandard primitives (functions and operators,
> indicated by a single symbol or a combination of a few symbols), it
> does not have function or operator precedence.»
>
> that cant be true, since function is a broad conception that includes
> any operators.
>
> But my question is about the statement that APL doesn't have operator
> precedence. As far as i know, in linear textual languages (as opposed
> to spread sheets, visual langs etc), unless it uses nested functional
> notation (e.g. Mathematica, lisp), i can't see how it can do without
> operator precedence?
>[...]
> So i think the Wikipedia statement “it does not have function or
> operator precedence” is wrong or needs qualifications.


It's been a while since I used APL but my recollection
is that operator precedence is very simple: left-to-right (*).
That is:

a op1 b op2 c op3 d

is parsed as:

(a op1 (b op2 (c op3 d)))

So I think the correct thing to say is that all APL
operators have the same precedence and are right-associative.

(*) I may be mis-remembering and operators are left-
associative but I am pretty sure about the equal precedence
part.
Reply With Quote
  #4  
Old 08-19-2008, 06:11 PM
xahlee@gmail.com
Guest
 
Default Re: Wikipedia article on APL has come of age!

On Aug 19, 3:09 pm, Stuart McGraw <smcg...@acedialup.com> wrote:
> xah...@gmail.com wrote:
> > according to
> >http://en.wikipedia.org/wiki/APL_(programming_language)

>
> > quote:
> > «As APL has many nonstandard primitives (functions and operators,
> > indicated by a single symbol or a combination of a few symbols), it
> > does not have function or operator precedence.»

>
> > that cant be true, since function is a broad conception that includes
> > any operators.

>
> > But my question is about the statement that APL doesn't have operator
> > precedence. As far as i know, in linear textual languages (as opposed
> > to spread sheets, visual langs etc), unless it uses nested functional
> > notation (e.g. Mathematica, lisp), i can't see how it can do without
> > operator precedence?
> >[...]
> > So i think the Wikipedia statement “it does not have function or
> > operator precedence” is wrong or needs qualifications.

>
> It's been a while since I used APL but my recollection
> is that operator precedence is very simple: left-to-right (*).
> That is:
>
> a op1 b op2 c op3 d
>
> is parsed as:
>
> (a op1 (b op2 (c op3 d)))
>
> So I think the correct thing to say is that all APL
> operators have the same precedence and are right-associative.
>
> (*) I may be mis-remembering and operators are left-
> associative but I am pretty sure about the equal precedence
> part.


Thanks.

Though your explanation doesn't cover binary operators. e.g. in

↑6?40

clearly it is
(↑(6?40))
and not
(↑(6(?40)))

Xah
http://xahlee.org/


Reply With Quote
  #5  
Old 08-19-2008, 06:19 PM
xahlee@gmail.com
Guest
 
Default Re: Wikipedia article on APL has come of age!

On Aug 19, 3:09 pm, Stuart McGraw <smcg...@acedialup.com> wrote:

> > So i think the Wikipedia statement “it does not have function or
> > operator precedence” is wrong or needs qualifications.

>
> It's been a while since I used APL but my recollection
> is that operator precedence is very simple: left-to-right (*).
> That is:
>
> a op1 b op2 c op3 d
>
> is parsed as:
>
> (a op1 (b op2 (c op3 d)))
>
> So I think the correct thing to say is that all APL
> operators have the same precedence and are right-associative.
>
> (*) I may be mis-remembering and operators are left-
> associative but I am pretty sure about the equal precedence
> part.



oops. My previous reply to you is a bit too fast.

What i mean is, from your reply, does that mean any binary operator in
APL is limited to just one occurance per line, and must be to the far
right?

Xah
http://xahlee.org/


Reply With Quote
  #6  
Old 08-19-2008, 07:08 PM
Bakul Shah
Guest
 
Default Re: Wikipedia article on APL has come of age!

xahlee@gmail.com wrote:
> On Aug 19, 3:09 pm, Stuart McGraw <smcg...@acedialup.com> wrote:
>
>>> So i think the Wikipedia statement “it does not have function or
>>> operator precedence” is wrong or needs qualifications.

>> It's been a while since I used APL but my recollection
>> is that operator precedence is very simple: left-to-right (*).
>> That is:
>>
>> a op1 b op2 c op3 d
>>
>> is parsed as:
>>
>> (a op1 (b op2 (c op3 d)))
>>
>> So I think the correct thing to say is that all APL
>> operators have the same precedence and are right-associative.
>>
>> (*) I may be mis-remembering and operators are left-
>> associative but I am pretty sure about the equal precedence
>> part.

>
>
> oops. My previous reply to you is a bit too fast.
>
> What i mean is, from your reply, does that mean any binary operator in
> APL is limited to just one occurance per line, and must be to the far
> right?
>
> Xah
> ∑ http://xahlee.org/
>
> ☄


They say it has no precedence rules because you parse from left to
right. A monadic function grabs the result of *everything* to its
right. A dyadic function grabs the result of everything to its right
and the item on its left. Use parentheses when the left operand is
to be computed from an expression. So for example you can do
(2 × 3) + 4 × 5
and get 26. (× is the multiply function).

I recommend you read Iverson's Turing Award lecture
http://elliscave.com/APL_J/tool.pdf
Reply With Quote
  #7  
Old 08-19-2008, 07:26 PM
xahlee@gmail.com
Guest
 
Default Re: Wikipedia article on APL has come of age!

On Aug 19, 4:08 pm, Bakul Shah <bakul+use...@bitblocks.com> wrote:
> ...
> They say it has no precedence rules because you parse from left to
> right. A monadic function grabs the result of *everything* to its
> right. A dyadic function grabs the result of everything to its right
> and the item on its left. Use parentheses when the left operand is
> to be computed from an expression. So for example you can do
> (2 × 3) + 4 × 5
> and get 26. (× is the multiply function).


That still does not explain fully how binary operation works without
precedence. For example

(2 × 3) + 4 × 5

becomes

6 + 4 × 5

But now, is it
6 + (4 × 5)
or
(6 + 4) × 5
?

from your explanation, it seems when when binary operator appear in
sequence, the right most has precedence??

but then, what happens when uninary and binary operator are combined,
as in

f 1 + 2

would that mean
f (1 + 2)
or
(f 1) + 2

> I recommend you read Iverson's Turing Award lecture
> http://elliscave.com/APL_J/tool.pdf


Thanks.

Xah
http://xahlee.org/


Reply With Quote
  #8  
Old 08-19-2008, 07:41 PM
xahlee@gmail.com
Guest
 
Default Re: Wikipedia article on APL has come of age!

On Aug 19, 4:26 pm, "xah...@gmail.com" <xah...@gmail.com> wrote:
> On Aug 19, 4:08 pm, Bakul Shah <bakul+use...@bitblocks.com> wrote:
>
> > ...
> > They say it has no precedence rules because you parse from left to
> > right. A monadic function grabs the result of *everything* to its
> > right. A dyadic function grabs the result of everything to its right
> > and the item on its left. Use parentheses when the left operand is
> > to be computed from an expression. So for example you can do
> > (2 × 3) + 4 × 5
> > and get 26. (× is the multiply function).


damn, post too past again.

Ok, summarizing posts in thread, it seems to be this:

in APL, there's uninary and binary operators.
When uninary operator are sequenced, right most takes precedence.
When binary are sequenced, the right most takes precedence.
When both are mixed, Binary operator has precedence than uninary.
Paren can be used to break the above precedence rule.

That seems to summarize it without ambiguity.

Though, it still has precedence, just a simple one though.

Xah
http://xahlee.org/


Reply With Quote
  #9  
Old 08-20-2008, 02:03 AM
xahlee@gmail.com
Guest
 
Default Re: Wikipedia article on APL has come of age!

On Aug 19, 9:15 pm, Paul Donnelly <paul-donne...@sbcglobal.net> wrote:
> "xah...@gmail.com" <xah...@gmail.com> writes:
> > according to
> >http://en.wikipedia.org/wiki/APL_(programming_language)

>
> > quote:
> > «As APL has many nonstandard primitives (functions and operators,
> > indicated by a single symbol or a combination of a few symbols), it
> > does not have function or operator precedence.»

>
> > that cant be true, since function is a broad conception that includes
> > any operators.

>
> > But my question is about the statement that APL doesn't have operator
> > precedence. As far as i know, in linear textual languages (as opposed
> > to spread sheets, visual langs etc), unless it uses nested functional
> > notation (e.g. Mathematica, lisp), i can't see how it can do without
> > operator precedence?

>
> > For example, in Wikipedia this code example for picking 6 random
> > numbers from 1 to 40:

>
> > ↑6?40

>
> > certainly there's operator precedence. e.g.

>
> > (↑(6?40))
> > (↑(6?)40)
> > (↑(6(?40)))
> > (↑6)(?40)

>
> > etc.

>
> > So i think the Wikipedia statement “it does not have function or
> > operator precedence” is wrong or needs qualifications.

>
> There are several other languages (that come to mind immediately) with
> no operator precedence rules. K and Q, descendents of APL, as well as
> Smalltalk (which doesn't have operators in the same way, but reads
> like it does). I believe the way APL, K, and Q do it is to group from
> right to left.
>
> 3*2+1 => 3*(2+1) => (3*(2+1)) => 9
> 1+2*3 => 1+(2*3) => (1+(2*3)) => 7
>
> ↑6?40 => ↑(6?40) => (↑(6?40)) => 3 4 6 11 24 30 (possibly)
>
> Deal 6 from 40 then sort the result. ↑ is sort when used as a unary
> function, and selects the first n from m when used like n↑m. The two
> cases can be distinguished by examining the thing to the left of ↑, if
> it's nothing or an operator, the function is unary, if it's a value
> the function is binary. If there happens to be more than one value to
> the right of an operator, it will take them all, I think. Parentheses
> can be used for explicit grouping.
>
> A←5 4 3 2
>
> ↓↑A
> Sort A then drop its first element => 3 4 5
>
> 2↑A
> Give me the first two elements of A => 5 4
>
> Smalltalk's parsing rules make it come out roughly the opposite way.
>
> 3*2+1 => (3*2)+1 => ((3*2)+1)
> 1+2*3 => (1+2)*3 => ((1+2)*3)
>
> I've only dabbled in these, so I may be wrong.


Thanks. I find the APL syntax rather elegant.

It occured to me, that in APL, there's no function/operator that has 3
or more argument?

If that's true, then i suppose any need for 3 or more arguments are
embeded as a 1-dimentional array aka vector?

What about optional parameters? How's APL deal with that?

Xah
http://xahlee.org/




Reply With Quote
  #10  
Old 08-20-2008, 02:17 AM
Bakul Shah
Guest
 
Default Re: Wikipedia article on APL has come of age!

xahlee@gmail.com wrote:
> On Aug 19, 4:26 pm, "xah...@gmail.com" <xah...@gmail.com> wrote:
>> On Aug 19, 4:08 pm, Bakul Shah <bakul+use...@bitblocks.com> wrote:
>>
>>> ...
>>> They say it has no precedence rules because you parse from left to
>>> right. A monadic function grabs the result of *everything* to its
>>> right. A dyadic function grabs the result of everything to its right
>>> and the item on its left. Use parentheses when the left operand is
>>> to be computed from an expression. So for example you can do
>>> (2 × 3) + 4 × 5
>>> and get 26. (× is the multiply function).

>
> damn, post too past again.
>
> Ok, summarizing posts in thread, it seems to be this:
>
> in APL, there's uninary and binary operators.
> When uninary operator are sequenced, right most takes precedence.
> When binary are sequenced, the right most takes precedence.
> When both are mixed, Binary operator has precedence than uninary.


First, an APL *operator* is much like a higher order function.
An APL primitive function is what you are calling an operator.
Primitive functions and user defined functions take 0, 1 or
2 operands and these are parsed strictly from right to left.
Thus
f 1 + 2 == f (1 + 2)
1 + f 2 == 1 + (f 2)
1 2 + 3 4 == (1 2) + (3 4)
1 - 2 + 3 4 == 1 - (2 + (3 4))
1 ++ 2 == 1 + (+ 2)
and so on. Yes, most primitive function symbols such as +
denote(usually) related unary and binary functions. And yes,
"1 2" is a vector and is treated as a single operand. Operators
like \ (scan) and / (insert -- what you may call foldl) do
have a higher binding strength. So "+/ 1 2 3" is parsed as
"(+/) (1 2 3)".

I should also say they are not just parsed but also *evaluated*
from left to right. So assignments affect the left side. So for
example
(-r) + r ← 1 2 3
will give you 0 0 0. If you are really interested, try to find
a free implementation (such as A+) and play with it. Or j or Q.
The latter two don't need any special APL font. See the FAQ on
comp.lang.apl for a list of implementations, documentation etc.
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 10:09 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.