Evaluation of APL direct functions

Here is a snippet I was testing recently. It takes two diameters (⍺,⍵) and computes the circumference of a circle:

10{(○1×⍺){⍺ ⍵}○1×⍵}10 ⍝ note the brackets around ⍺
  31.4159 31.4159
10{○1×⍺{⍺ ⍵}○1×⍵}10
  31.4159 98.696

I would like to understand how evaluation of this expression works - why is the first one evaluating correctly and the second one isn't?

I am using Dyalog APL.


You have nested functions. In both cases, the inner function simply returns its right and left argument. In the first case, the left argument to the inner function is the expression (○ 1×⍺), in the second case the left argument to the inner function is simply ⍺, or the unaltered left argument of the outer function -- then entire result of the inner function is multiplied by ○ and by 1.

Note that the argument to the circle function is everything to its right so the 1 x is totally redundant.

In APL, expressions are evaluated right to left. We can say that function applies to everything to its right unless modified by parens. Therefore we could say that in the first expression ○ takes 1 multiplied by everything to its right which is only ⍺ due to the parentheses. But in the second expression ○ takes 1 multiplied by everything to its right which is the result of the inner function.

Furthermore, note that due to scalar extension, you can compute the two numbers with no braces at all:

      ○10 10
31.415926535898 31.415926535898

More interesting with a different diameters:

     ○10 15 20
31.415926535898 47.123889803847 62.831853071796

Need Your Help

How can I simulate ext3 filesystem corruption?

linux testing filesystems fault-tolerance ext3

I would like to simulate filesystem corruption for the purpose of testing how our embedded systems react to it and ultimately have them fail as gracefully as possible. We use different kinds of block

Specifying cells in excel using TCOM

excel tcl

The command $cells Item 2 A {SomeText} doesn't set the text in the cell A2 instead it assigns the text in the cell A1. Any idea on why its behaving like this???

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.