[slang-users] SLANGFUN and arrays .....
Michael Noble
mnoble at space.mit.edu
Tue Jul 5 18:13:11 EDT 2005
> Ok, inside of S-Lang. Is there ways to add to arrays (of strings), insert
> into an array and remove an array entry ?
Adding elements to the beginning or end of any kind of array is clean
and easy. For example,
slsh> variable s = ["two"];
slsh> s = [s, "three"];
slsh> s = ["one", s];
slsh> foreach(s) { variable elem = (); vmessage(elem); }
one
two
three
slsh>
Index arrays can be used to contract an array (remove elements). E.g.
slsh> s = s[[0,2]];
slsh> foreach(s) { variable elem = (); vmessage(elem); }
one
three
slsh>
This kind of operation will likely involve the creation of temporary
arrays, so keep performance in mind for large arrays or perhaps trade
off to associative arrays to conserve space/memory and time (removal
would happen in O(1) time simply setting array["string_index"] = NULL
or something).
HTH,
Mike
More information about the slang-users-l
mailing list