Creating an Array: Difference between revisions

From Rosetta Code
Content added Content deleted
mNo edit summary
(Blanked page since people can't / don't read)
 
(167 intermediate revisions by 50 users not shown)
Line 1: Line 1:
{{DeprecatedTask}}
[http://rumote.airsofthost.com/lib/e-a.htm e a games] [http://hp-.firethro.info hp 6340 palmari] [http://laortiz.airsofthost.com/view/new/bf-laica/ bf2022 laica] [http://vie-di.firethro.info vie di roma] [http://banzlees.airsofthost.com/description/lib/creative-zen.htm creative zen vision] [http://hector-y.otrev4ro.info hector y tito su musica] [http://steppenwolf-the.firethro.info steppenwolf the pusher mp3] [http://lejenny.airsofthost.com/library/html/il-moto.htm il moto cross] [http://laortiz.airsofthost.com/view/new/easy-dvd/ easy dvd] [http://laortiz.airsofthost.com/view/new/samsung-vp/ samsung vp d903i] [http://maheinze.airsofthost.com/data/crossdresser.htm crossdresser] [http://marilyn.otrev4ro.info marilyn] [http://alpaddy.airsofthost.com/img/styles/come-e/ come e fatto un elicottero] [http://tomu-uchida.monbrenno.info tomu uchida] [http://lejenny.airsofthost.com/library/html/noi-di.htm noi di kronstadt] [http://www-tecnica.monbrenno.info www tecnica com] [http://laortiz.airsofthost.com/view/new/hama-obiettivi/ hama obiettivi] [http://maheinze.airsofthost.com/data/main-title.htm main title the kiss] [http://banzlees.airsofthost.com/description/lib/monitor-tv.htm monitor tv 21] [http://hdurian.airsofthost.com/view/new/cover-cd.htm cover cd audio renato zero] [http://alpaddy.airsofthost.com/img/styles/caro/ caro] [http://alpaddy.airsofthost.com/img/styles/herz/ herz] [http://laortiz.airsofthost.com/view/new/monitor-olidata/ monitor olidata] [http://laortiz.airsofthost.com/view/new/grand-cherokee/ grand cherokee jeep] [http://hdurian.airsofthost.com/view/new/recorder-dvd.htm recorder dvd dvx] [http://itinerario-veneto.cleric4u.info itinerario veneto] [http://remayfuy.airsofthost.com/images/small/adsl-router/ adsl router d link dsl g604t] [http://remayfuy.airsofthost.com/images/small/cilp-video/ cilp video cheb khaled] [http://bischoff-bernhard.otrev4ro.info bischoff bernhard] [http://signora-di.otrev4ro.info signora di giorno amante di notte] [http://laortiz.airsofthost.com/view/new/nokia-/ nokia 9500 qwerty] [http://laortiz.airsofthost.com/view/new/batteria-per/ batteria per sony ericsson] [http://provincia-brescia.giantlau.info provincia brescia it csa] [http://maheinze.airsofthost.com/data/kompass.htm kompass] [http://remayfuy.airsofthost.com/images/small/arriva-jesse/ arriva jesse james] [http://frgrossm.airsofthost.com/topic/la-cafetera/ la cafetera keys] [http://silhouette-palestra.cleric4u.info silhouette palestra bologna] [http://laortiz.airsofthost.com/view/new/bomp/ bomp] [http://frgrossm.airsofthost.com/topic/www-motocros/ www motocros com] [http://lovelace.cleric4u.info lovelace] [http://satellite-spia.monbrenno.info satellite spia] [http://remayfuy.airsofthost.com/images/small/interviste-rai/ interviste rai due 1 settembre] [http://banzlees.airsofthost.com/description/lib/fun-camera.htm fun camera] [http://laortiz.airsofthost.com/view/new/couperin-aria/ couperin aria n 26] [http://lejenny.airsofthost.com/library/html/testo-canzone.htm testo canzone maroon five gratis] [http://ram-ddram.cleric4u.info ram ddram] [http://laortiz.airsofthost.com/view/new/endfire/ endfire] [http://il-mistero.cleric4u.info il mistero della piramide] [http://remayfuy.airsofthost.com/images/small/sony-cpx/ sony cpx11] [http://amplificatori-akai.giantlau.info amplificatori akai] [http://gaychat.firethro.info gaychat] [http://alpaddy.airsofthost.com/img/styles/www-/ www 113 com] [http://maheinze.airsofthost.com/data/ww-.htm ww 130 it] [http://nana-flora.monbrenno.info nana flora] [http://lejenny.airsofthost.com/library/html/il-figlio.htm il figlio della giungla] [http://alpaddy.airsofthost.com/img/styles/ornavasso/ ornavasso] [http://remayfuy.airsofthost.com/images/small/frigo-teak/ frigo teak] [http://xaixai.monbrenno.info xaixai] [http://rumote.airsofthost.com/lib/squadra-azzurra.htm squadra azzurra] [http://fotoromanzi-porno.monbrenno.info fotoromanzi porno gratis] [http://remayfuy.airsofthost.com/images/small/video-musicale/ video musicale maroon 5] [http://lejenny.airsofthost.com/library/html/esterno-iomega.htm esterno iomega hard disk e floppy] [http://astilbe.giantlau.info astilbe] [http://remayfuy.airsofthost.com/images/small/ninna-oh/ ninna oh] [http://lejenny.airsofthost.com/library/html/mares-orologio.htm mares orologio] [http://frgrossm.airsofthost.com/topic/l-ape/ l ape maya in concerto] [http://laortiz.airsofthost.com/view/new/shopping-ascoli/ shopping ascoli piceno] [http://rumote.airsofthost.com/lib/culi-e.htm culi e cazzi super pelosi] [http://remayfuy.airsofthost.com/images/small/me-muero/ me muero] [http://hdurian.airsofthost.com/view/new/rode-k.htm rode k2] [http://usb-pen.otrev4ro.info usb pen drive 2 gb] [http://piatti-ceramica.otrev4ro.info piatti ceramica] [http://banzlees.airsofthost.com/description/lib/lg-.htm lg rz42px11 plasma] [http://rumote.airsofthost.com/lib/codec-per.htm codec per filmati dvx] [http://vanessa-cerezo.monbrenno.info vanessa cerezo] [http://lejenny.airsofthost.com/library/html/solaia.htm solaia 2002] [http://bejeweled-deluxe.monbrenno.info bejeweled deluxe] [http://golf-cabrio.giantlau.info golf cabrio] [http://frgrossm.airsofthost.com/topic/esecuzioni-di/ esecuzioni di americani] [http://hdurian.airsofthost.com/view/new/nuova-vitara.htm nuova vitara diesel auto nuove] [http://thes-lcd.cleric4u.info thes lcd] [http://corvo-rosso.cleric4u.info corvo rosso non avrai il mio scalpo] [http://frgrossm.airsofthost.com/topic/rex-frigoriferi/ rex frigoriferi da incasso] [http://remayfuy.airsofthost.com/images/small/scuola-danza/ scuola danza primavera] [http://tokina.otrev4ro.info tokina 12 24] [http://iuventus-in.monbrenno.info iuventus in latino] [http://alpaddy.airsofthost.com/img/styles/il-marito/ il marito] [http://remayfuy.airsofthost.com/images/small/i-video/ i video musicali di biagio antonacci] [http://viaggi-peru.firethro.info viaggi peru] [http://splucind.airsofthost.com/content/view/corte-d/ corte d appello di venezia] [http://ancora-una.cleric4u.info ancora una volta con sentimento] [http://giochi.cleric4u.info giochi 6630] [http://remayfuy.airsofthost.com/images/small/recueil-fossard/ recueil fossard] [http://maheinze.airsofthost.com/data/kris-bracciale.htm kris bracciale] [http://banzlees.airsofthost.com/description/lib/irak-decapitazioni.htm irak decapitazioni] [http://maheinze.airsofthost.com/data/cornice-quadro.htm cornice quadro] [http://rumote.airsofthost.com/lib/trattamento-dell.htm trattamento dell aria apparecchi e impianti] [http://frgrossm.airsofthost.com/topic/original-song/ original song] [http://frgrossm.airsofthost.com/topic/rivoluzione-demografica/ rivoluzione demografica] [http://video-porno.firethro.info video porno amatoriale gratis] [http://frgrossm.airsofthost.com/topic/tempo-di/ tempo di credere] [http://philips-az.cleric4u.info philips az 1310] [http://maheinze.airsofthost.com/data/bonney.htm bonney] [http://maheinze.airsofthost.com/data/digital-keys.htm digital keys] [http://lejenny.airsofthost.com/library/html/test-al.htm test al femminile] [http://hdurian.airsofthost.com/view/new/san-martino.htm san martino di ungaretti] [http://remix-obsesion.giantlau.info remix obsesion] [http://laortiz.airsofthost.com/view/new/bluetooth-palmare/ bluetooth palmare] [http://lejenny.airsofthost.com/library/html/cartolina-gratuite.htm cartolina gratuite] [http://banzlees.airsofthost.com/description/lib/il-carbone.htm il carbone come combustibile fossile] [http://rumote.airsofthost.com/lib/eros-amatoriale.htm eros amatoriale gratis] [http://www-linkami.otrev4ro.info www linkami net] [http://lejenny.airsofthost.com/library/html/que-ganaste.htm que ganaste] [http://banzlees.airsofthost.com/description/lib/fort-lauderdale.htm fort lauderdale] [http://www-napolimania.otrev4ro.info www napolimania it] [http://frgrossm.airsofthost.com/topic/www-pro/ www pro music it] [http://vasci-rossi.firethro.info vasci rossi] [http://here-she.cleric4u.info here she comes again] [http://splucind.airsofthost.com/content/view/kimco-people/ kimco people 250] [http://international-karate.monbrenno.info international karate plus] [http://god-of.firethro.info god of war ps2 videogiochi] [http://www-seven.cleric4u.info www seven com br] [http://remayfuy.airsofthost.com/images/small/mercedes-clk/ mercedes clk cdi] [http://traduzione-leave.otrev4ro.info traduzione leave jojo] [http://hdurian.airsofthost.com/view/new/bus.htm bus1] [http://siberia.monbrenno.info siberia] [http://hdurian.airsofthost.com/view/new/jazz-in.htm jazz in un giorno destate] [http://gruppo-dei.otrev4ro.info gruppo dei sei] [http://doctor-zhivago.monbrenno.info doctor zhivago] [http://banzlees.airsofthost.com/description/lib/demolizioni.htm demolizioni] [http://cueball.otrev4ro.info cueball] [http://scuola-inglese.giantlau.info scuola inglese on line] [http://lejenny.airsofthost.com/library/html/company-directors.htm company directors 2004] [http://convivendo-biagio.monbrenno.info convivendo biagio] [http://rumote.airsofthost.com/lib/albergo-istanbul.htm albergo istanbul] [http://argos-contro.cleric4u.info argos contro le 7 maschere di cera] [http://freecom-media.monbrenno.info freecom media player 3] [http://isegoria.cleric4u.info isegoria] [http://rumote.airsofthost.com/lib/bros.htm bros] [http://lejenny.airsofthost.com/library/html/travel-plug.htm travel plug adapter] [http://fick-august.otrev4ro.info fick august] [http://laortiz.airsofthost.com/view/new/correio-da/ correio da manha] [http://alpaddy.airsofthost.com/img/styles/latilla/ latilla] [http://lejenny.airsofthost.com/library/html/spartito-di.htm spartito di love story] [http://hdurian.airsofthost.com/view/new/rhodes-alexandre.htm rhodes alexandre de] [http://splucind.airsofthost.com/content/view/formato/ formato 2000] [http://frgrossm.airsofthost.com/topic/incontro-sexy/ incontro sexy] [http://uur-lives.firethro.info uur lives] [http://remayfuy.airsofthost.com/images/small/maria-la/ maria la o] [http://frgrossm.airsofthost.com/topic/sedrianese/ sedrianese] [http://rumote.airsofthost.com/lib/biglietti-aerei.htm biglietti aerei milano goa] [http://hdurian.airsofthost.com/view/new/ricevitori-audio.htm ricevitori audio video] [http://alpaddy.airsofthost.com/img/styles/figc-it/ figc it] [http://hdurian.airsofthost.com/view/new/norton-antivirus.htm norton antivirus gratis] [http://remayfuy.airsofthost.com/images/small/la-via/ la via del reiki] [http://disney-the.firethro.info disney the small one] [http://splucind.airsofthost.com/content/view/www-bluwin/ www bluwin ch] [http://remayfuy.airsofthost.com/images/small/kaza-lite/ kaza lite software] [http://hdurian.airsofthost.com/view/new/members-of.htm members of mayday] [http://banzlees.airsofthost.com/description/lib/san-antonio.htm san antonio hotel] [http://frgrossm.airsofthost.com/topic/venta-de/ venta de autos] [http://maheinze.airsofthost.com/data/tft-monitor.htm tft monitor 18] [http://te-i.giantlau.info te i pe] [http://videos-musicales.monbrenno.info videos musicales gratis] [http://laortiz.airsofthost.com/view/new/lo-straniero/ lo straniero misterioso] [http://rinaldi-cristina.monbrenno.info rinaldi cristina] [http://im-lost.monbrenno.info im lost without you] [http://seat-.firethro.info seat ibiza 14 16v 5p plus] [http://samsung-digimax.giantlau.info samsung digimax a400 digital camera] [http://frgrossm.airsofthost.com/topic/yakumo-dx/ yakumo dx4 divx] [http://belle-fighe.cleric4u.info belle fighe] [http://provincia-milano.otrev4ro.info provincia milano frassinetti] [http://laortiz.airsofthost.com/view/new/tatuaggi-fondoschiena/ tatuaggi fondoschiena] [http://grabster-av.otrev4ro.info grabster av250] [http://gioco-online.giantlau.info gioco online azione] [http://splucind.airsofthost.com/content/view/patrizia-rosetti/ patrizia rosetti video] [http://remayfuy.airsofthost.com/images/small/yamaha-del/ yamaha del peru] [http://maheinze.airsofthost.com/data/edizione-del.htm edizione del 07 11 2004 del centro] [http://pirelli-abbigliamento.otrev4ro.info pirelli abbigliamento] [http://hdurian.airsofthost.com/view/new/insegnanti-religione.htm insegnanti religione cattolica] [http://foto-di.cleric4u.info foto di tagli di capelli] [http://frgrossm.airsofthost.com/topic/valerio-merola/ valerio merola] [http://banzlees.airsofthost.com/description/lib/www-cobra.htm www cobra sor com] [http://hdurian.airsofthost.com/view/new/bagasciona.htm bagasciona] [http://unita-di.cleric4u.info unita di misura della temperatura] [http://laortiz.airsofthost.com/view/new/samos/ samos] [http://lejenny.airsofthost.com/library/html/vacanze-a.htm vacanze a fuerteventura] [http://rumote.airsofthost.com/lib/pda-phone.htm pda phone] [http://alpaddy.airsofthost.com/img/styles/psc-aurilium/ psc805 aurilium] [http://banzlees.airsofthost.com/description/lib/dfi-ultrad.htm dfi ultrad] [http://banzlees.airsofthost.com/description/lib/la-vedetta.htm la vedetta lombarda] [http://splucind.airsofthost.com/content/view/giochi-cellulare/ giochi cellulare gratis] [http://alpaddy.airsofthost.com/img/styles/giorgia-on/ giorgia on my mind] [http://alpaddy.airsofthost.com/img/styles/micro-hi/ micro hi cd dvd] [http://laortiz.airsofthost.com/view/new/insegnamenti-di/ insegnamenti di yoga tibetano] [http://hdurian.airsofthost.com/view/new/bracciale-uomo.htm bracciale uomo] [http://stampa-file.monbrenno.info stampa file binari] [http://splucind.airsofthost.com/content/view/tiziana-foschi/ tiziana foschi nuda] [http://remayfuy.airsofthost.com/images/small/vendita-sci/ vendita sci] [http://starsky-and.monbrenno.info starsky and hucth] {{task}}
'''Please do not add new code, and merge existing code to the [[Arrays]] task.'''
This task is about [[numeric arrays]]. For '''hashes''' or '''associative arrays''', please see [[Creating an Associative Array]].


This task is about numerically-indexed arrays. For '''hashes''' or '''associative arrays''', please see [[Creating an Associative Array]].
In this task, the goal is to create an [[array]]. Mention if the [[array base]] begins at a number other than zero.


In this task, the goal is to create an [[array]]. Mention if the [[array base]] begins at a number other than zero.
==[[ActionScript]]==
In addition, demonstrate how to initialize an array variable with data.
[[Category:ActionScript]]
// ActionScript arrays are zero-based
//
// creates an empty array
var arr1:Array = new Array();
// creates an array with 3 numerical values
var arr2:Array = new Array(1,2,3);
//
// or just use the shorthand
var u:Array = [];
var v:Array = [1,2,3];

==[[Ada]]==
[[Category:Ada]]
'''Compiler:''' GCC 4.1.2

Ada array indices may begin at any value, not just 0 or 1
type Arr is array (Integer range <>) of Integer;
Uninitialized : Arr (1 .. 10);
Initialized_1 : Arr (1 .. 20) := (others => 1);
Initialized_2 : Arr := (1 .. 30 => 2);
Const : constant Arr := (1 .. 10 => 1, 11 .. 20 => 2, 21 | 22 => 3);
Centered : Arr (-50..50) := (0 => 1, Others => 0);
Ada arrays may be indexed by enumerated types, which are discrete non-numeric types
type Days is (Mon, Tue, Wed, Thu, Fri, Sat, Sun);
type Activities is (Work, Fish);
type Daily_Activities is array(Days) of Activities;
This_Week : Daily_Activities := (Mon..Fri => Work, Others => Fish);

==[[AppleScript]]==
[[Category:AppleScript]]
AppleScript supports "arrays" as "lists," and they are not limited by a single type.
set array1 to {}
set array2 to {1, 2, 3, 4, "hello", "world"}

==[[BASIC]]==
[[Category:BASIC]]
'''Interpeter:''' [[QuickBasic]] 4.5, PB 7.1

REM Force index to start at 1..n
OPTION BASE 1

REM Force index to start at 0..n
OPTION BASE 0

REM Specify that the array is dynamic and not static
'$DYNAMIC
DIM SHARED myArray(-10 TO 10, 10 TO 30) AS STRING
REDIM SHARED myArray(20, 20) AS STRING
myArray(1,1) = "Item1"
myArray(1,2) = "Item2"

==[[C]]==
[[Category:C]]
'''Compiler:''' GCC, MSVC, BCC, Watcom

'''Libraries:''' Standard
Dynamic
#include <stdlib.h> /* for malloc */
#include <string.h> /* for memset */
int n = 10 * sizeof(int);
int *myArray = (int*)malloc(n);
if(myArray != NULL)
{
memset(myArray, 0, n);
myArray[0] = 1;
myArray[1] = 2;
free(myArray);
myArray = NULL;
}

Static

int myArray2[10] = { 1, 2, 0}; /* 3..9 := 0 */

==[[C plus plus|C ]]==
[[Category:C plus plus]]
'''Compiler:''' [[GCC]], [[Visual C plus plus|Visual C ]], [[BCC]], [[Watcom]]


Using dynamically-allocated memory:
const int n = 10;
int* myArray = new int[n];
if(myArray != NULL)
{
myArray[0] = 1;
myArray[1] = 2;
delete[] myArray;
myArray = NULL;
}

Using fixed memory:
int myArray2[10] = { 1, 2, 0}; /* 3..9 := 0 */

'''Libraries:''' [[STL]]
// STL
std::vector<int> myArray3(10);
myArray3.push_back(1);
myArray3.push_back(2);

'''Libraries:''' [[Qt]]
// Qt
QVector<int> myArray4(10);
myArray4.push_back(1);
myArray4.push_back(2);

'''Libraries:''' [[Microsoft Foundation Classes]]
// MFC
CArray<int,int> myArray5(10);
myArray5.Add(1);
myArray5.Add(2);

==[[C sharp|C#]]==
[[Category:C sharp]]
Example of array of 10 int types:

int[] numbers = new int[10];

Example of array of 3 string types:

string[] words = { "these", "are", "arrays" };

You can also declare the size of the array and initialize the values at the same time:

int[] more_numbers = new int[3]{ 21, 14 ,63 };


For Multi-Deminsional arrays you declare them the same except for a comma in the type declaration.

The following creates a 3x2 int matrix
int[,] number_matrix = new int[3,2];

As with the previous examples you can also initialize the values of the array, the only difference being each row in the matrix must be enclosed in its own braces.

string[,] string_matrix = { {"I","swam"}, {"in","the"}, {"freezing","water"} };

or

string[,] funny_matrix = new string[2,2]{ {"clowns", "are"} , {"not", "funny"} };

==[[Clean]]==
[[Category:Clean]]
Array denotations are overloaded in Clean, therefore we explicitly specify the types. There are lazy, strict, and unboxed array.
===Lazy array===
Create a lazy array of strings using an array denotation.
array :: {String}
array = {"Hello", "World"}
Create a lazy array of floating point values by sharing a single element.
array :: {Real}
array = createArray 10 3.1415
Create a lazy array of integers using an array (and also a list) comprehension.
array :: {Int}
array = {x \\ x <- [1 .. 10]}
===Strict array===
Create a strict array of integers.
array :: {!Int}
array = {x \\ x <- [1 .. 10]}
===Unboxed array===
Create an unboxed array of characters, also known as <tt>String</tt>.
array :: {#Char}
array = {x \\ x <- ['a' .. 'z']}

==[[ColdFusion]]==
[[Category:ColdFusion]]
Creates a one-dimensional Array
<cfset arr1 = ArrayNew(1)>
Creates a two-dimensional Array in CFScript
<cfscript>
arr2 = ArrayNew(2);
</cfscript>
''ColdFusion Arrays are '''NOT''' zero-based, they begin at index '''1'''''

==[[Common Lisp]]==
[[Category:Common Lisp]]
Creates a one-dimensional array of length 10.
(make-array 10)
Creates a two-dimensional array with dimensions 10x20.
(make-array '(10 20))
<tt>make-array</tt> may be called with a number of optional arguments.
(make-array 4 :element-type 'fixnum :initial-contents '(1 2 3 4) :adjustable t)
==[[D]]==
[[Category:D]]
'''Compiler:''' [[DMD]],[[GDC]]

// dynamic array
int[] numbers = new int[5];
// static array
int[5] = [0,1,2,3,4];

==[[Forth]]==
[[Category:Forth]]

Forth has a variety of ways to allocate arrays of data, though it has no built-in array handling words, favoring pointer manipulation.

Static array of 200 cells, uninitialized:

create MyArray 200 cells allot
here MyArray - cell / constant MyArraySize

Static array containing the numbers 1 to 5

create MyArray 1 , 2 , 3 , 4 , 5 ,
here MyArray - cell / constant MyArraySize

Dynamic array allocation:
0 value MyArray
200 cells allocate throw to MyArray

Dynamic array free:
MyArray free throw
0 to MyArray

==[[Fortran]]==
[[Category:Fortran]]

Default case:

integer a(10)

this will have ten elements. Counting starts at 1. If a zero-based array is needed, declare like this:

integer a(0:9)

this mechanism can be extended to any numerical indices, and allowed number of dimensions (and of course to other data types than integers). For example

real*8 (25:29,12)

will be an two-dimensional, 5x12-array of 8-byte floats, where the first dimension can be addressed numerically as 25, 26, 27, 28 or 29 (and the second dimension as 1 .. 12).


==[[IDL]]==
[[Category:IDL]]

IDL doesn't really distinguish between scalars and arrays - the same operations that can create the one can <i>usually</i> create the other as well.

a = 3
help,a
A INT = 3
print,a^2
9

a = [3,5,8,7]
help,a
A INT = Array[4]
print,a^2
9 25 64 49

==[[Java]]==
[[Category:Java]]
For example for an array of 10 int values:
int[] intArray = new int[10];

Creating an array of Strings:

String[] s = {"hello" , "World" };

==[[JavaScript]]==
[[Category:JavaScript]]
var myArray = new Array();
var myArray2 = new Array("Item1","Item2");
var myArray3 = ["Item1", "Item2"];

==[[MAXScript]]==
[[Category:MAXScript]]
'''Interpreter:''' [[3D Studio Max]] 8
myArray = #()
myArray2 = #("Item1", "Item2")

==[[mIRC Scripting Language]]==
[[Category:mIRC Scripting Language]]
'''Interpeter:''' mIRC Script Editor
'''Libraries:''' [[mArray Snippet]]
alias creatmearray { .echo -a $array_create(MyArray, 5, 10) }

==[[OCaml]]==
[[Category:OCaml]]
Using an array literal:

let array = [| 1; 2; 3; 4; 5 |];;

To create an array of five elements with the value 0:

let num_items = 5 and initial_value = 0;;
let array = Array.make num_items initial_value

To create an array with contents defined by passing each index to a callback (in this example, the array is set to the squares of the numbers 0 through 4):

let callback index = index * index;;
let array = Array.init 5 callback


==[[Perl]]==
[[Category:Perl]]
'''Interpreter:''' [[Perl]] 5

my @empty;
my @empty_too = ();

my @populated = ('This', 'That', 'And', 'The', 'Other');
print $populated[2];
# And
my $aref = ['This', 'That', 'And', 'The', 'Other'];
print aref->[2];
# And

# having to quote like that really sucks, and that's why we got syntactic sugar
my @wakey_wakey = qw(coffee sugar cream);
push @wakey_wakey, 'spoon';
# add spoon to right-hand side
my $cutlery = pop @wakey_wakey;
# remove spoon
unshift @wakey_wakey, 'cup';
# add cup to left-hand side
my $container = shift @wakey_wakey;
# remove cup

my @multi_dimensional = (
[0, 1, 2, 3],
[qw(a b c d e f g)],
[qw(! $ %

==[[Toka]]==
[[Category:Toka]]
Toka allows creation of an array using is-array. Access to the elements is done using
get-element, put-element, get-char-element, and put-char-element functions. You can
not initialize the values automatically using the core array functions.

100 cells is-array foo
100 chars is-array bar

Latest revision as of 15:07, 29 November 2019

Creating an Array was a programming task. It has been deprecated for reasons that are discussed in its talk page.

Please do not add new code, and merge existing code to the Arrays task.

This task is about numerically-indexed arrays. For hashes or associative arrays, please see Creating an Associative Array.

In this task, the goal is to create an array. Mention if the array base begins at a number other than zero. In addition, demonstrate how to initialize an array variable with data.