Apply a callback to an array: Difference between revisions

Moved the REXX language to it's proper place alphabetically. -- ~~~~
m (→‎{{header|SuperCollider}}: sorry for the noise, I'm incompetent)
(Moved the REXX language to it's proper place alphabetically. -- ~~~~)
Line 1,402:
 
<lang Retro>[ "Hello" "World" "Foo" ] ^array'fromQuote [ "%s " puts ] ^array'apply</lang>
 
=={{header|RLaB}}==
RLaB has two type of arrays: 'standard' or 1-dimensional, that can be a row-
or a column-vectory; and, 'associative' which are called lists.
For standard array its entry identifier (index) is an integer in
range 1:N where N is the size of the array.
For associative array its entry identifier is a string consisting of printable
ASCII characters.
 
All scalar mathematical functions are 'matrix-optimized' meaning that if the argument
to a function is a matrix, then the return value of the function is a matrix of the
same size as the input argument, where the function is applied to the individual entries
of the matrix.
Consider an example:
 
<lang RLaB>
>> x = rand(2,4)
0.707213207 0.275298961 0.396757763 0.232312312
0.215619868 0.207078017 0.565700032 0.666090571
>> sin(x)
0.649717845 0.271834652 0.386430003 0.230228332
0.213952984 0.205601224 0.536006923 0.617916954
</lang>
 
This can be done on entry-by-entry basis, but one has to keep in mind that the
'for' or 'while' loops are slow in interpreted languages, and RLaB is no exception.
 
<lang RLaB>
x = rand(2,4);
y = zeros(2,4);
for (i in 1:2)
{
for (j in 1:4)
{
y[i;j] = sin( x[i;j] );
}
}
</lang>
 
 
The functions can take lists as arguments, but then it has to be specified within the body
of the function what to do with the list elements. Given a list call it 'x' there is a RLaB
function 'members' which returns a string vector with the names of the elements of the list.
 
<lang RLaB>
x = <<>>;
for (i in 1:9)
{
x.[i] = rand();
}
 
y = <<>>;
for (i in members(x))
{
y.[i] = sin( x.[i] );
}
</lang>
 
 
=={{header|REXX}}==
Line 1,539 ⟶ 1,481:
after b.10=3628800
</pre>
 
=={{header|RLaB}}==
RLaB has two type of arrays: 'standard' or 1-dimensional, that can be a row-
or a column-vectory; and, 'associative' which are called lists.
For standard array its entry identifier (index) is an integer in
range 1:N where N is the size of the array.
For associative array its entry identifier is a string consisting of printable
ASCII characters.
 
All scalar mathematical functions are 'matrix-optimized' meaning that if the argument
to a function is a matrix, then the return value of the function is a matrix of the
same size as the input argument, where the function is applied to the individual entries
of the matrix.
Consider an example:
 
<lang RLaB>
>> x = rand(2,4)
0.707213207 0.275298961 0.396757763 0.232312312
0.215619868 0.207078017 0.565700032 0.666090571
>> sin(x)
0.649717845 0.271834652 0.386430003 0.230228332
0.213952984 0.205601224 0.536006923 0.617916954
</lang>
 
This can be done on entry-by-entry basis, but one has to keep in mind that the
'for' or 'while' loops are slow in interpreted languages, and RLaB is no exception.
 
<lang RLaB>
x = rand(2,4);
y = zeros(2,4);
for (i in 1:2)
{
for (j in 1:4)
{
y[i;j] = sin( x[i;j] );
}
}
</lang>
 
 
The functions can take lists as arguments, but then it has to be specified within the body
of the function what to do with the list elements. Given a list call it 'x' there is a RLaB
function 'members' which returns a string vector with the names of the elements of the list.
 
<lang RLaB>
x = <<>>;
for (i in 1:9)
{
x.[i] = rand();
}
 
y = <<>>;
for (i in members(x))
{
y.[i] = sin( x.[i] );
}
</lang>
 
=={{header|Ruby}}==