slang-users mailing list

[2005 Date Index] [2005 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Re: [slang-users] SLANGFUN and arrays .....


> 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

_______________________________________________
To unsubscribe, visit http://jedsoft.org/slang/mailinglists.html


[2005 date index] [2005 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]