Article View: comp.lang.misc
Article #6877Re: Arrays in languages
From: Steven Pemberton
Date: Wed, 07 Mar 1990 16:39
Date: Wed, 07 Mar 1990 16:39
67 lines
2515 bytes
2515 bytes
In article <9230@wpi.wpi.edu> jhallen@wpi.wpi.edu (Joseph H Allen) writes:
> (the nicest array language I've ever used was a version of BASIC which
> didn't have a DIM statement but which handled arrays of arbitrary
> dimension and size. I.E., you could just say 'A(1,5,10)=7' and it
> would allocate the array for you. You could then say 'A(1,5,10,8)=9'
> and it would make the element A(1,5,10) contain a sub-array... Is
> there any other language with this power?
Sure! ABC, recently posted to the net (but *still* not appeared on
binaries.{mac, ibm.pc} and sources.unix - what are those moderators
doing?) has the equivalent:
- no declaration of arrays, or their sizes
- dynamically sized
- sparse
For instance (>>> is the ABC prompt; it's an interactive language):
>>> PUT {} IN tel \ initialises tel to empty
>>> PUT 4141 IN tel["Eddy"]
>>> PUT 4999 IN tel["Babs"]
>>> PUT 7878 IN tel["Lambert"]
>>> WRITE tel["Babs"]
4999
>>> WRITE tel \ you can write the whole array
{["Babs"]: 4999; ["Eddy"]: 4141; ["Lambert"]: 7878}
>>> WRITE keys tel
{"Babs"; "Eddy"; "Lambert"}
>>> FOR name IN keys tel:
WRITE name, ":", tel[name] /
Babs: 4999
Eddy: 4141
Lambert: 7878
Similarly with 'multi-dimension' arrays:
>>> PUT {} IN value
>>> PUT 1 IN value[5, 8]
>>> PUT 13 IN value[3, 6]
>>> PUT -1 IN value[1, 9]
>>> WRITE value[3, 6]
13
>>> WRITE value
{[1, 9]: -1; [3, 6]: 13; [5, 8]: 1}
>>> WRITE keys value
{(1, 9); (3, 6); (5, 8)}
Actually the keys here are single values of type 'compound', so you
may also say things like
>>> PUT 1, 9 IN point
>>> WRITE value[point]
-1
>>> IF point1 IN keys value: WRITE value[point1]
etc.
Steven Pemberton, CWI, Amsterdam; steven@cwi.nl
"Let us go then you and I/while the night is laid out against the sky/like a
smear of mustard on an old pork pie"
Nice poem Tom. I have ideas for changes though, why not come over? - Ezra
Technical Details
Message-ID:
<8873@boring.cwi.nl>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!mailrus!uunet!mcsun!hp4nl!charon!stevenReferences:
<3528@tukki.jyu.fi> <14251@lambda.UUCP> <8836@boring.cwi.nl> <14255@lambda.UUCP> <8849@boring.cwi.nl> <9230@wpi.wpi.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!mailrus!uunet!mcsun!hp4nl!charon!steven From: steven@cwi.nl (Steven Pemberton) Newsgroups: comp.lang.misc Subject: Re: Arrays in languages Message-ID: <8873@boring.cwi.nl> Date: 7 Mar 90 16:39:00 GMT References: <3528@tukki.jyu.fi> <14251@lambda.UUCP> <8836@boring.cwi.nl> <14255@lambda.UUCP> <8849@boring.cwi.nl> <9230@wpi.wpi.edu> Sender: news@cwi.nl (The Daily Dross) Reply-To: steven@valk.cwi.nl.UUCP (Steven Pemberton) Organization: CWI, Amsterdam Lines: 67