# array questions..

James Witte jswitte at bloomington.in.us
Tue Oct 15 12:52:01 EDT 2002

```> Some beginner's questions about arrays - not vital questions, but I'm
> curious...

Is tehre a way to do "slice" or "slice-like" assignment to arrays (as in
Perl)?  Can I say 'put [5,3,4,2] into z[4..7]' where z in an array?  Or
just 'put [1,2,5,4,6,7] into z / put [1,4,5,6] after z'.  (Would that last
one put them in as new elements?

Also kind of related, can procedures return multiple values like in Perl
(without using hashs).  Something like:

function sumAndDifference(x y)
return (x+y), (x-y)
end sumAndDifference

-- main program

put 0 into sum
put sumAndDifference(6,5) into sum,diff
put sum && diff
-- gives "11 1

> like:
> 5,1
> 3,3
> 3,1
> 1,5
> 1,3
> 5,2

>  We> ... and so on. It is surely quite logical, but rather difficult to
> understand for a mere biologist!

I'd imagine that the arrays are actually hash
tables, where the is no definite decernible order to how the keys come
out. (I'm assumming that the 'keys' function just goes through memory in
order' wehreas the creating of the key uses a complicated hash value of
that key and won't neccessarily come up in order (a typical hash function
would be:

put 0 into val
repeat for each char k in string
end repeat
put val mod 51 into val

-- the modulus at the end should be a prime for optimal table
non-clustering, and the multiplier on the alphanumeric factor might be
important too to be a prime

Of course, this kind of hash table is almost a neccesity if your're
dealing with variables like myArray("this") myArray("that") myArray("cat")
and such, but with straight numeric addresses, I'd think a standard C-type
array structure might be more efficient - of course, implmenting that as a
hash table as well lets you add new keys in at will (say you have keys
1,2,3,5,and 6, then wanted to add the 4 key in later.  No imagine doing
this in a two-dimensional array with a "hole" or two in it.)

Jim

```