Array programming: Difference between revisions

Content deleted Content added
Internal link
Tags: Visual edit Mobile edit Mobile web edit
Rmv duplicate wiki links WP:DUPLINK
Line 7:
The fundamental idea behind array programming is that operations apply at once to an entire set of values. This makes it a [[high-level programming language|high-level programming]] model as it allows the programmer to think and operate on whole aggregates of data, without having to resort to explicit loops of individual scalar operations.
 
[[Kenneth E. Iverson]] described the rationale behind array programming (actually referring to [[APL (programming language)|APL]]) as follows:<ref>{{cite journal |author= Iverson, K. E. |title= Notations as a Tool of Thought. |journal= Communications of the ACM |volume= 23 |issue= 8 |pages= 444–465 |year= 1980 |url= http://www.jsoftware.com/papers/tot.htm |access-date= 2011-03-22 |doi= 10.1145/358896.358899 |archive-url= https://web.archive.org/web/20130920071911/http://www.jsoftware.com/papers/tot.htm |archive-date= 2013-09-20 |url-status= dead |author-link= Kenneth E. Iverson |doi-access= free }}</ref>
{{quote|most programming languages are decidedly inferior to mathematical notation and are little used as tools of thought in ways that would be considered significant by, say, an applied mathematician.
The thesis is that the advantages of executability and universality found in programming languages can be effectively combined, in a single coherent language, with the advantages offered by mathematical notation. it is important to distinguish the difficulty of describing and of learning a piece of notation from the difficulty of mastering its implications. For example, learning the rules for computing a matrix product is easy, but a mastery of its implications (such as its associativity, its distributivity over addition, and its ability to represent linear functions and geometric operations) is a different and much more difficult matter.
Line 24:
 
==Languages==
The canonical examples of array programming languages are [[Fortran]], [[APL (programming language)|APL]], and [[J programming language|J]]. Others include: [[A+ (programming language)|A+]], [[Analytica (software)|Analytica]], [[Chapel (programming language)|Chapel]], [[IDL (programming language)|IDL]], [[Julia (programming language)|Julia]], [[K (programming language)|K]], Klong, [[Q (programming language from Kx Systems)|Q]], Mata, [[MATLAB]], [[MOLSF]], [[NumPy]], [[GNU Octave]], [[Perl Data Language|PDL]], [[R (programming language)|R]], [[S-Lang (programming language)|S-Lang]], [[SAC programming language|SAC]], [[Nial programming language|Nial]], [[ZPL (programming language)|ZPL]] and [[TI-BASIC]].
 
===Scalar languages===
Line 34:
</syntaxhighlight>
 
In array-based languages, for example in [[Fortran]], the nested for-loop above can be written in array-format in one line,
<syntaxhighlight lang="fortran">
a = a + b
Line 55:
 
====APL====
[[APL (programming language)|APL]] uses single character Unicode symbols with no syntactic sugar.
<syntaxhighlight lang="apl">
A ← A + B
Line 175:
 
====MATLAB====
The implementation in [[MATLAB]] allows the same economy allowed by using the [[Fortran]] language.
<syntaxhighlight lang="matlab">
A = A + B;
</syntaxhighlight>
 
A variant of the MATLAB language is the [[GNU Octave]] language, which extends the original language with [[augmented assignment]]sassignments:
<syntaxhighlight lang="octave">
A += B;
Line 203:
 
====R====
The [[R (programming language)|R]] language supports [[array paradigm]] by default. The following example illustrates a process of multiplication of two matrices followed by an addition of a scalar (which is, in fact, a one-element vector) and a vector:
<syntaxhighlight lang="r">
> A <- matrix(1:6, nrow=2) !!this has nrow=2 ... and A has 2 rows