On Tue, 2007-11-06 at 18:42 -0800, Oleg Kobchenko wrote:
> Well but control structures have not become first class citizens as they are
> in C.
> Why is u/ not equivalent to a loop?
> There is a very severe performance penalty.
> Lisp/SmallTalk can be defined by itself.
> But because in APL control structure are deficient, it cannot.
> That's the whole mud vs diamond argument; and this control flow issue
> is at its core.
The SISAL designers did a very good job, IMO, on control structures.
I think any designer of functional array languages would do well
to look closely at what they did:
ALL control structures in SISAL are functional, like the
functional C notation:
x = cond ? truevalue : falsevalue;
This is the functional equivalent of:
if (cond) {
x = truevalue;
} else {
x = falsevalue:
}
except that the functional form is a clear, readable guarantee that x
has a
value when the expression completes. This simplifies analysis and makes
the code terser and more readable. Had the C designers merely switched
the order to make it:
x = cond ? falsevalue : truevalue;
they could have extended this to be a case statement:
x = indexexpression ? valuefor0 : valuefor1 : valuefor2 : ...;
The SISAL designers took this functional expression
further, and made ALL control structures
functional. For instance, the SISAL FOR loop is side-effect-free,
producing
a set of arrays as its result. Like with the above C notation,
it simplifies analysis.
Function arrays and the gerunds of J are a start in this direction,
but I do not think they comprise a complete solution.
Performance: Although your claim about u/x having superior performance
to a
loop, this is only true in an interpreted environment. In a compiled
environment, their performance is much closer. The main advantages
of u/x are then: (1) better readability and (2) obvious data
parallelism.
The latter may be present in a loop, but is generally harder to spot,
particularly if the spotter is a compiler or interpreter.
Less is more.
Bob
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm