Array: Difference between revisions
Content added Content deleted
m (lang link fixing) |
(not a task; don't use {{header}}) |
||
Line 29: | Line 29: | ||
In most programming languages, arrays are accessed by using the array brackets <tt>[</tt> and <tt>]</tt>, e.g. in <tt>A[i]</tt>, but exceptions exist, including [[Rexx]] which instead uses the dot operator <tt>.</tt>, such as in <tt>A.i</tt>; [[Fortran]], [[Ada]] and [[BASIC]] which use round parentheses <tt>A(i)</tt>, and in [[LISP|lisp]] dialects which use constructions like <tt>(ELT A n)</tt> for accessing and <tt>(SETA A n new_val)</tt> for setting (Interlisp) or <tt>(vector-ref A n)</tt> for accessing and <tt>(vector-set! A n new_val)</tt> for setting (Scheme). No bracket indexing occurs in [[J]], an array language; instead, the normal syntax of function creation and function calling applies. |
In most programming languages, arrays are accessed by using the array brackets <tt>[</tt> and <tt>]</tt>, e.g. in <tt>A[i]</tt>, but exceptions exist, including [[Rexx]] which instead uses the dot operator <tt>.</tt>, such as in <tt>A.i</tt>; [[Fortran]], [[Ada]] and [[BASIC]] which use round parentheses <tt>A(i)</tt>, and in [[LISP|lisp]] dialects which use constructions like <tt>(ELT A n)</tt> for accessing and <tt>(SETA A n new_val)</tt> for setting (Interlisp) or <tt>(vector-ref A n)</tt> for accessing and <tt>(vector-set! A n new_val)</tt> for setting (Scheme). No bracket indexing occurs in [[J]], an array language; instead, the normal syntax of function creation and function calling applies. |
||
⚫ | |||
⚫ | |||
⚫ | |||
==Examples== |
|||
⚫ | |||
We wish to open a text file and compute letter frequency |
We wish to open a text file and compute letter frequency |
||
Line 52: | Line 57: | ||
} |
} |
||
==[[J]]== |
===[[J]]=== |
||
The example task is the same: open a text file and compute letter frequency. |
The example task is the same: open a text file and compute letter frequency. |
||
<br>Written in this array programming language, no loops are specified. |
<br>Written in this array programming language, no loops are specified. |
||
Line 65: | Line 70: | ||
) |
) |
||
==[[OCaml]]== |
===[[OCaml]]=== |
||
same task, open a text file and compute letter frequency |
same task, open a text file and compute letter frequency |
||
Line 86: | Line 91: | ||
Here is [http://caml.inria.fr/pub/docs/manual-ocaml/libref/Array.html the documentation] of the module Array. (there is also a [http://caml.inria.fr/pub/docs/manual-ocaml/libref/Bigarray.html Bigarray module]) |
Here is [http://caml.inria.fr/pub/docs/manual-ocaml/libref/Array.html the documentation] of the module Array. (there is also a [http://caml.inria.fr/pub/docs/manual-ocaml/libref/Bigarray.html Bigarray module]) |
||
== |
===[[Pascal]]=== |
||
This defines an array suitable to hold a 64x64 truecolor image (i.e. red, green and blue RGB values all can go from 0 to 255) and then sets the color of a single pixel |
This defines an array suitable to hold a 64x64 truecolor image (i.e. red, green and blue RGB values all can go from 0 to 255) and then sets the color of a single pixel |
||
<lang pascal> |
<lang pascal> |
||
Line 104: | Line 109: | ||
</lang> |
</lang> |
||
== |
===[[Python]]=== |
||
Example: open a text file and compute letter frequency. |
Example: open a text file and compute letter frequency. |
||
<lang python> |
<lang python> |
||
Line 162: | Line 167: | ||
Again eliminating all fussing with the details of converting letters into list indices. |
Again eliminating all fussing with the details of converting letters into list indices. |
||
⚫ | |||
⚫ | |||
[[Category:Data Structures]] |
[[Category:Data Structures]] |