Creating an Array: Difference between revisions
(→[[Common Lisp]]: comment on initial contents; fixnum is a bad habit) |
mNo edit summary |
||
Line 1: | Line 1: | ||
[http://pupsik1993.ifrance.com/linkimp-park.html linkimp park] [http://katzella.ifrance.com/horscopes-english/index.html horscopes english] [http://thecrownless.ifrance.com/isole-eolie/index.html isole eolie] [http://busjavka.ifrance.com/hotel-rovigni-croazia/index.html hotel rovigni croazia] [http://angeljazz711.ifrance.com/inni-e-marce-terzo-reich.html inni e marce terzo reich] [http://oddonpurpose.ifrance.com/lectores-cd-ron.html lectores cd ron] [http://snakeystil.ifrance.com/johnson-decap/index.html johnson decap] [http://fluffy-mind.ifrance.com/klite-codec.html klite codec] [http://risdimpuka.ifrance.com/la-fiesta-del-burrito/index.html la fiesta del burrito] [http://carbonphoenix.ifrance.com/jimmi-fontana.html jimmi fontana] [http://listmishyk.ifrance.com/kameron/index.html kameron] [http://carbonphoenix.ifrance.com/jose-luiz-rodriguez.html jose luiz rodriguez] [http://starcross33.ifrance.com/loiarro-michele/index.html loiarro michele] [http://carbonphoenix.ifrance.com/jessyca-nue.html jessyca nue] [http://child-ofadot.ifrance.com/il-canto-del.html il canto del cardellino] [http://busjavka.ifrance.com/hit-mania-dance-1997/index.html hit mania dance 1997] [http://snakeystil.ifrance.com/jesus-crist-supestar/index.html jesus crist supestar] [http://listmishyk.ifrance.com/kivircik/index.html kivircik] [http://oddonpurpose.ifrance.com/mulatte.html mulatte] [http://oddonpurpose.ifrance.com/laguna-blu-bonitas.html laguna blu bonitas] [http://eliasn5gh.ifrance.com/lyrics-to-songs-karaoke.html lyrics to songs karaoke lyrics] [http://pupsik1993.ifrance.com/lo-ciento.html lo ciento] [http://starcross33.ifrance.com/leva-voce/index.html leva voce] [http://cuivenarius.ifrance.com/hunchback-disney.html hunchback disney] [http://chasingspaces.ifrance.com/ginger-linn/index.html ginger linn] [http://taylors-acolyte.ifrance.com/irgilio.html irgilio] [http://carbonphoenix.ifrance.com/juan-afonso-baptista.html juan afonso baptista] [http://chasingspaces.ifrance.com/haka/index.html haka] [http://snakeystil.ifrance.com/jessica-simpon/index.html jessica simpon] [http://chasingspaces.ifrance.com/hackerz/index.html hackerz] [http://busjavka.ifrance.com/haiduk-vs-gabri/index.html haiduk vs gabri ponte] [http://starcross33.ifrance.com/la-vita-e-bela/index.html la vita e bela] [http://busjavka.ifrance.com/hobbits/index.html hobbits] [http://alexandraa80.ifrance.com/laura-muraskaite/index.html laura muraskaite] [http://taylors-acolyte.ifrance.com/i-m-holding-out-for.html i m holding out for a hero] [http://listmishyk.ifrance.com/kral-i-sluga/index.html kral i sluga] [http://thecrownless.ifrance.com/inni-degli-alpini/index.html inni degli alpini] [http://cuivenarius.ifrance.com/hobbastank-the-reason.html hobbastank the reason] [http://snakeystil.ifrance.com/jaennete/index.html jaennete] [http://katzella.ifrance.com/hospice/index.html hospice] [http://listmishyk.ifrance.com/kate-playground/index.html kate playground] [http://xxxenichkaa.ifrance.com/l-amore-e-la.html l amore e la gilosia] [http://xxxenichkaa.ifrance.com/la-vita-di-verga.html la vita di verga] [http://risdimpuka.ifrance.com/lia-zoppelli/index.html lia zoppelli] [http://plyuh-vios.ifrance.com/in-bagno-in.html in bagno in aereoporto] [http://thecrownless.ifrance.com/il-sildino/index.html il sildino] [http://angeljazz711.ifrance.com/indymedia-it.html indymedia it] [http://thecrownless.ifrance.com/il-barattolo/index.html il barattolo] [http://thecrownless.ifrance.com/insieme-per-cordenons/index.html insieme per cordenons] [http://starcross33.ifrance.com/lyric-this-love/index.html lyric this love] [http://starcross33.ifrance.com/los-telez/index.html los telez] [http://listmishyk.ifrance.com/konami-italia/index.html konami italia] [http://listmishyk.ifrance.com/katia-nuda-del-grande/index.html katia nuda del grande fratello] [http://taylors-acolyte.ifrance.com/iubitel.html iubitel] [http://starcross33.ifrance.com/lospicapiedras/index.html lospicapiedras] [http://taylors-acolyte.ifrance.com/i-gens-in-fondo-al-viale.html i gens in fondo al viale] [http://taylors-acolyte.ifrance.com/i-was-made-to.html i was made to love you polly paulusma] [http://cuivenarius.ifrance.com/haiducci-dragstea.html haiducci dragstea din tei] [http://katzella.ifrance.com/hino-barcelona/index.html hino barcelona] [http://starcross33.ifrance.com/legislazione/index.html legislazione] [http://chasingspaces.ifrance.com/haris/index.html haris] [http://thecrownless.ifrance.com/ida-rendano/index.html ida rendano] [http://carbonphoenix.ifrance.com/jumatate.html jumatate] [http://thecrownless.ifrance.com/interferone-collirio/index.html interferone collirio] [http://pupsik1993.ifrance.com/luis-borges.html luis borges] [http://cuivenarius.ifrance.com/hombre-con-mujeres.html hombre con mujeres] [http://xxxenichkaa.ifrance.com/la-mazurka-di-peiferia.html la mazurka di peiferia] [http://plyuh-vios.ifrance.com/il-pene-piu-lunghi.html il pene piu lunghi del mondo] [http://cuivenarius.ifrance.com/hombres-eroticos.html hombres eroticos] [http://risdimpuka.ifrance.com/le-vivrazioni/index.html le vivrazioni] [http://xxxenichkaa.ifrance.com/liif.html liif] [http://thecrownless.ifrance.com/il-commissario-pepe/index.html il commissario pepe] [http://plyuh-vios.ifrance.com/il-sito-ufficiale-di.html il sito ufficiale di avril] [http://oddonpurpose.ifrance.com/la-temible-lluvia-acida.html la temible lluvia acida] [http://cuivenarius.ifrance.com/horizon.html horizon] [http://oddonpurpose.ifrance.com/la-psicologia-dei.html la psicologia dei sogni] [http://pupsik1993.ifrance.com/legge-sul-lavoro.html legge sul lavoro videosorveglianza art 4] [http://taylors-acolyte.ifrance.com/idroguide.html idroguide] [http://eliasn5gh.ifrance.com/liven-la-vida.html liven la vida loca] [http://taylors-acolyte.ifrance.com/immobiliare-terranuova.html immobiliare terranuova] [http://oddonpurpose.ifrance.com/l-ultimo-invito.html l ultimo invito] [http://child-ofadot.ifrance.com/informatica.html informatica] [http://alexandraa80.ifrance.com/lido-iesolo/index.html lido iesolo] [http://eliasn5gh.ifrance.com/la-blancura.html la blancura] [http://katzella.ifrance.com/hey-baby-video/index.html hey baby video] [http://taylors-acolyte.ifrance.com/immenso-amedeo.html immenso amedeo minghi] [http://oddonpurpose.ifrance.com/little-kevin-263.html little kevin 263] [http://busjavka.ifrance.com/hotel-mille-aosta/index.html hotel mille aosta] [http://katzella.ifrance.com/haloween/index.html haloween] [http://taylors-acolyte.ifrance.com/italia-sex-oral.html italia sex oral] [http://katzella.ifrance.com/iznad-tesnja/index.html iznad tesnja] [http://starcross33.ifrance.com/los-cuarenta-winter-2004/index.html los cuarenta winter 2004] [http://oddonpurpose.ifrance.com/laundromat.html laundromat] [http://katzella.ifrance.com/ivonne/index.html ivonne] [http://taylors-acolyte.ifrance.com/i-dimonios.html i dimonios] [http://angeljazz711.ifrance.com/isole-cicladi.html isole cicladi] [http://chasingspaces.ifrance.com/hayfa-wehbe/index.html hayfa wehbe] [http://xxxenichkaa.ifrance.com/lido-dante.html lido dante] [http://taylors-acolyte.ifrance.com/immobiliare-vasto.html immobiliare vasto] [http://xxxenichkaa.ifrance.com/latichat-com.html latichat com] [http://busjavka.ifrance.com/hard-core-teen-sex/index.html hard core teen sex] [http://risdimpuka.ifrance.com/linciaggi/index.html linciaggi] [http://plyuh-vios.ifrance.com/inno-dei-carristi.html inno dei carristi] [http://starcross33.ifrance.com/la-solitudine/index.html la solitudine] [http://eliasn5gh.ifrance.com/libia-cartina.html libia cartina] [http://angeljazz711.ifrance.com/iwan-delfin-jej-czrne.html iwan delfin jej czrne oczy] [http://cuivenarius.ifrance.com/happy-people.html happy people] [http://listmishyk.ifrance.com/ktft/index.html ktft] [http://taylors-acolyte.ifrance.com/immunologia.html immunologia] [http://xxxenichkaa.ifrance.com/le-fighe-bestialiti.html le fighe bestialiti] [http://chasingspaces.ifrance.com/hide-u/index.html hide u] [http://child-ofadot.ifrance.com/it-is-you-i-have.html it is you i have loved] [http://plyuh-vios.ifrance.com/immagini-natale.html immagini natale] [http://busjavka.ifrance.com/hitmaniadance-99/index.html hitmaniadance 99] [http://snakeystil.ifrance.com/juegosxxx/index.html juegosxxx] [http://katzella.ifrance.com/haum/index.html haum] [http://child-ofadot.ifrance.com/itik.html itik] [http://busjavka.ifrance.com/hero-tayler/index.html hero tayler] [http://thecrownless.ifrance.com/il-solito-renato/index.html il solito renato] [http://plyuh-vios.ifrance.com/italiani-emigrati.html italiani emigrati in brasile] [http://angeljazz711.ifrance.com/incantesimi-streghe.html incantesimi streghe] [http://chasingspaces.ifrance.com/hooligans/index.html hooligans] [http://listmishyk.ifrance.com/katia-price/index.html katia price] [http://angeljazz711.ifrance.com/iraq-omicidi.html iraq omicidi] [http://fluffy-mind.ifrance.com/kylie-minogue.html kylie minogue i believe in you] [http://cuivenarius.ifrance.com/horkyze-slize-l-a.html horkyze slize l a g song] [http://chasingspaces.ifrance.com/gem-boy-canzoni/index.html gem boy canzoni] [http://chasingspaces.ifrance.com/graduatorie-trasferimenti/index.html graduatorie trasferimenti] [http://taylors-acolyte.ifrance.com/incontri-milano.html incontri milano] [http://eliasn5gh.ifrance.com/lascate-mi.html lascate mi] [http://carbonphoenix.ifrance.com/jvm.html jvm] [http://xxxenichkaa.ifrance.com/loops-merengue.html loops merengue] [http://eliasn5gh.ifrance.com/l-oceano-del-silenzio.html l oceano del silenzio] [http://taylors-acolyte.ifrance.com/i-p-a.html i p a] [http://busjavka.ifrance.com/holz-michl/index.html holz michl] [http://pupsik1993.ifrance.com/le-casalinghe.html le casalinghe rhoss 2003] [http://taylors-acolyte.ifrance.com/il-bardo.html il bardo] [http://chasingspaces.ifrance.com/hack-sign/index.html hack sign] [http://angeljazz711.ifrance.com/i-vini-italiani.html i vini italiani] [http://cuivenarius.ifrance.com/hoobastank-video.html hoobastank video] [http://angeljazz711.ifrance.com/i-don-t-wonna-kb.html i don t wonna kb now] [http://angeljazz711.ifrance.com/iorio.html iorio] [http://xxxenichkaa.ifrance.com/lupi.html lupi] [http://child-ofadot.ifrance.com/il-salva-vita-beghelli.html il salva vita beghelli dove si trova] [http://chasingspaces.ifrance.com/hotmajl/index.html hotmajl] [http://carbonphoenix.ifrance.com/jame-lee-curtis.html jame lee curtis] [http://snakeystil.ifrance.com/jannes/index.html jannes] [http://plyuh-vios.ifrance.com/internazionale.html internazionale socialista mp3] [http://xxxenichkaa.ifrance.com/lyra.html lyra] [http://alexandraa80.ifrance.com/los-guns-n-roses/index.html los guns n roses] [http://carbonphoenix.ifrance.com/janet-jackson-love.html janet jackson love me for a little while] [http://cuivenarius.ifrance.com/hip-hop-instrumental.html hip hop instrumental] [http://fluffy-mind.ifrance.com/kathrine-and-waves.html kathrine and waves] [http://katzella.ifrance.com/hetor-y-tito/index.html hetor y tito] [http://fluffy-mind.ifrance.com/kolomeke.html kolomeke] [http://carbonphoenix.ifrance.com/juliana-paaes.html juliana paaes] [http://oddonpurpose.ifrance.com/lista-teatri.html lista teatri] [http://eliasn5gh.ifrance.com/lsa-vuelta.html lsa vuelta] [http://katzella.ifrance.com/houtson-i-like/index.html houtson i like that] [http://plyuh-vios.ifrance.com/i-m-so-sexy.html i m so sexy] [http://pupsik1993.ifrance.com/libro-giulietta.html libro giulietta euna] [http://oddonpurpose.ifrance.com/l-arte-neoclassica.html l arte neoclassica] [http://pupsik1993.ifrance.com/los-amantes-de-lola.html los amantes de lola] [http://starcross33.ifrance.com/la-princesa-diana/index.html la princesa diana] [http://xxxenichkaa.ifrance.com/la-costa-del.html la costa del silencio del mago de oz] [http://busjavka.ifrance.com/hombres-guapos-desnudos/index.html hombres guapos desnudos] [http://oddonpurpose.ifrance.com/la-carota.html la carota] [http://snakeystil.ifrance.com/jana-jankulovski/index.html jana jankulovski] [http://xxxenichkaa.ifrance.com/l-amore-ci-cambia.html l amore ci cambia la vita gianni morandi] [http://snakeystil.ifrance.com/joe-cassano-bean/index.html joe cassano bean] [http://chasingspaces.ifrance.com/hiroshi-oshima/index.html hiroshi oshima] [http://oddonpurpose.ifrance.com/luglio-agosto-settembre.html luglio agosto settembre nero] [http://taylors-acolyte.ifrance.com/il-rugby.html il rugby] [http://starcross33.ifrance.com/lindsay-williams/index.html lindsay williams] [http://starcross33.ifrance.com/lettore/index.html lettore] [http://cuivenarius.ifrance.com/hulio-iglesias.html hulio iglesias] [http://busjavka.ifrance.com/hotel-canaletto/index.html hotel canaletto venezia] [http://chasingspaces.ifrance.com/hex-kiosque/index.html hex kiosque] [http://cuivenarius.ifrance.com/hot-tango.html hot tango] [http://katzella.ifrance.com/hijo-tuta/index.html hijo tuta] [http://taylors-acolyte.ifrance.com/il-video-della-decapitazione.html il video della decapitazione di bigley] [http://cuivenarius.ifrance.com/http-susanna80-da-ru.html http susanna80 da ru] [http://taylors-acolyte.ifrance.com/isla-del-carmen.html isla del carmen com] [http://pupsik1993.ifrance.com/los-angels-guida.html los angels guida turistica] [http://oddonpurpose.ifrance.com/lea-de-mae.html lea de mae] [http://oddonpurpose.ifrance.com/life-deriree.html life deriree] [http://child-ofadot.ifrance.com/i-don-t-wanna-know-marion.html i don t wanna know marion winans] [http://snakeystil.ifrance.com/jo-dassin/index.html jo dassin] [http://busjavka.ifrance.com/hooverphonic/index.html hooverphonic] [http://oddonpurpose.ifrance.com/linea-77-video.html linea 77 video] [http://xxxenichkaa.ifrance.com/lizzie-mcguire.html lizzie mcguire com] [http://carbonphoenix.ifrance.com/joke-a-day.html joke a day] [http://cuivenarius.ifrance.com/haddon-heights-high.html haddon heights high] [http://carbonphoenix.ifrance.com/jugo-de-col-roja.html jugo de col roja] [http://xxxenichkaa.ifrance.com/loredana-di-cicco.html loredana di cicco nuda] [http://child-ofadot.ifrance.com/ispap.html ispap] [http://fluffy-mind.ifrance.com/key-files.html key files] [http://eliasn5gh.ifrance.com/la-mesa-que-mas.html la mesa que mas aplauda] [http://taylors-acolyte.ifrance.com/in-volo.html in volo] [http://alexandraa80.ifrance.com/la-venere-bianca/index.html la venere bianca] {{task}} |
|||
{{task}} |
|||
This task is about [[numeric arrays]]. For '''hashes''' or '''associative arrays''', please see [[Creating an Associative Array]]. |
This task is about [[numeric arrays]]. For '''hashes''' or '''associative arrays''', please see [[Creating an Associative Array]]. |
||
Revision as of 02:50, 1 September 2007
linkimp park horscopes english isole eolie hotel rovigni croazia inni e marce terzo reich lectores cd ron johnson decap klite codec la fiesta del burrito jimmi fontana kameron jose luiz rodriguez loiarro michele jessyca nue il canto del cardellino hit mania dance 1997 jesus crist supestar kivircik mulatte laguna blu bonitas lyrics to songs karaoke lyrics lo ciento leva voce hunchback disney ginger linn irgilio juan afonso baptista haka jessica simpon hackerz haiduk vs gabri ponte la vita e bela hobbits laura muraskaite i m holding out for a hero kral i sluga inni degli alpini hobbastank the reason jaennete hospice kate playground l amore e la gilosia la vita di verga lia zoppelli in bagno in aereoporto il sildino indymedia it il barattolo insieme per cordenons lyric this love los telez konami italia katia nuda del grande fratello iubitel lospicapiedras i gens in fondo al viale i was made to love you polly paulusma haiducci dragstea din tei hino barcelona legislazione haris ida rendano jumatate interferone collirio luis borges hombre con mujeres la mazurka di peiferia il pene piu lunghi del mondo hombres eroticos le vivrazioni liif il commissario pepe il sito ufficiale di avril la temible lluvia acida horizon la psicologia dei sogni legge sul lavoro videosorveglianza art 4 idroguide liven la vida loca immobiliare terranuova l ultimo invito informatica lido iesolo la blancura hey baby video immenso amedeo minghi little kevin 263 hotel mille aosta haloween italia sex oral iznad tesnja los cuarenta winter 2004 laundromat ivonne i dimonios isole cicladi hayfa wehbe lido dante immobiliare vasto latichat com hard core teen sex linciaggi inno dei carristi la solitudine libia cartina iwan delfin jej czrne oczy happy people ktft immunologia le fighe bestialiti hide u it is you i have loved immagini natale hitmaniadance 99 juegosxxx haum itik hero tayler il solito renato italiani emigrati in brasile incantesimi streghe hooligans katia price iraq omicidi kylie minogue i believe in you horkyze slize l a g song gem boy canzoni graduatorie trasferimenti incontri milano lascate mi jvm loops merengue l oceano del silenzio i p a holz michl le casalinghe rhoss 2003 il bardo hack sign i vini italiani hoobastank video i don t wonna kb now iorio lupi il salva vita beghelli dove si trova hotmajl jame lee curtis jannes internazionale socialista mp3 lyra los guns n roses janet jackson love me for a little while hip hop instrumental kathrine and waves hetor y tito kolomeke juliana paaes lista teatri lsa vuelta houtson i like that i m so sexy libro giulietta euna l arte neoclassica los amantes de lola la princesa diana la costa del silencio del mago de oz hombres guapos desnudos la carota jana jankulovski l amore ci cambia la vita gianni morandi joe cassano bean hiroshi oshima luglio agosto settembre nero il rugby lindsay williams lettore hulio iglesias hotel canaletto venezia hex kiosque hot tango hijo tuta il video della decapitazione di bigley http susanna80 da ru isla del carmen com los angels guida turistica lea de mae life deriree i don t wanna know marion winans jo dassin hooverphonic linea 77 video lizzie mcguire com joke a day haddon heights high jugo de col roja loredana di cicco nuda ispap key files la mesa que mas aplauda in volo la venere bianca
You are encouraged to solve this task according to the task description, using any language you may know.
This task is about numeric 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.
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
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
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
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
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
Compiler: GCC, 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#
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
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 String.
array :: {#Char} array = {x \\ x <- ['a' .. 'z']}
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
Creates a one-dimensional array of length 10. The initial contents are undefined.
(make-array 10)
Creates a two-dimensional array with dimensions 10x20.
(make-array '(10 20))
make-array may be called with a number of optional arguments.
(make-array 4 :element-type 'integer :initial-contents '(1 2 3 4) :adjustable t)
D
// dynamic array int[] numbers = new int[5]; // static array int[5] = [0,1,2,3,4];
E
[] # immutable, empty [1,9,17] # immutable, 3 elements [].diverge() # mutable, empty [].diverge(int) # mutable, integers only
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
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
IDL doesn't really distinguish between scalars and arrays - the same operations that can create the one can usually 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
For example for an array of 10 int values:
int[] intArray = new int[10];
Creating an array of Strings:
String[] s = {"hello" , "World" };
JavaScript
var myArray = new Array(); var myArray2 = new Array("Item1","Item2"); var myArray3 = ["Item1", "Item2"];
MAXScript
Interpreter: 3D Studio Max 8
myArray = #() myArray2 = #("Item1", "Item2")
mIRC Scripting Language
Interpeter: mIRC Script Editor Libraries: mArray Snippet
alias creatmearray { .echo -a $array_create(MyArray, 5, 10) }
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
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
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