Re: Possible feature for new Euphoria-version

new topic     » goto parent     » topic index » view thread      » older message » newer message

On Thu, 08 Jan 2004 19:54:28 +0100, Tommy Carlier
<tommy.carlier at pandora.be> wrote:

>Sequences are really easy to use, but there is no way you can create an 
>index to a sub-, sub-, sub-sequence of a given sequence. Wouldn't it be 
>nice if such a thing existed?

My apologies if you already knew how to code such, but this might just
(possibly) be all you are after:

function getqx(sequence q, sequence i)
	if length(i)=1 then
		return q[i[1]]
	end if
	return getqx(q[i[1]],i[2..length(i)])
end function

function setqx(sequence q, sequence i, object val)
	if length(i)=1 then
		q[i[1]]=val
		return q
	end if
	q[i[1]]=setqx(q[i[1]],i[2..length(i)],val)
	return q
end function

sequence s
s = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
integer a
? getqx(s,{2,2})			-- prints 5
s=setqx(s,{2,2},123)
?s					-- prints {{1, 2, 3}, {4, 123, 6}, {7, 8, 9}}
if getc(0) then end if
abort(0)

I'm not (too) worried about having to code get() like this, but set()
will probably impose serious COW (copy-on-write) overhead
unnecessarily when used with large sequences.

Of course I believe indexing using sequences should be part of a new
improved Euphoria, btw, but that's not going to be here for a while
yet, so maybe in the meantime the above will be of some use.

Regards,
Pete

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu