Igor Schein on Tue, 19 Nov 2002 18:08:11 -0500


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: extension of vecextract()


On Tue, Nov 19, 2002 at 11:52:20PM +0100, Karim BELABAS wrote:
> On Mon, 18 Nov 2002, Igor Schein wrote:
> > let's say I have a vector and I wanna insert an element into it:
> >
> > \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
> > ? v=["a","b","c","d"];
> >
> > \\ inserting an element at 3rd position:
> >
> > ? concat([vecextract(v,3),[1],vecextract(v,12)])
> > ["a", "b", 1, "c", "d"]
> > \\ or
> > ? w=[1,2];concat([vecextract(v,w),[1],vecextract(v,eval(setminus(Set(vector(4,k,k)),Set(w))))])
> > ["a", "b", 1, "c", "d"]
> > \\ or
> > ? concat([vecextract(v,"1..2"),[1],vecextract(v,"3..4")])
> > ["a", "b", 1, "c", "d"]
> >
> > \\ however, if I wanna insert it in the beginning or in the end:
> >
> > ? concat([vecextract(v,15),[1],vecextract(v,0)])
> > ["a", "b", "c", "d", 1]
> > \\ or
> > ? w=[1,2,3,4];concat([vecextract(v,w),[1],vecextract(v,eval(setminus(Set(vector(4,k,k)),w)))])
> > ["a", "b", "c", "d", 1]
> > \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
> >
> > There's no way to do it with ".." mechanism
> >
> > So maybe it's a good idea to extend ".." mechanism to be consistent
> > with the other two?
> 
> I don't get it. What exact command would you like to run, and with what
> expected result ?

I guess something like this:

? concat([vecextract(v,"1..4"),[1],vecextract(v,"5")])
["a", "b", "c", "d", 1]

\\ and

? concat([vecextract(v,"0"),[1],vecextract(v,"1..4")])
[1, "a", "b", "c", "d"]

> 
> [ Btw, what's wrong with concat(v, [1]), concat([1], v) ? ]

This works fine of course standalone, but if I'm doing it in a loop with ".."
mechanism, the logic would be smth like:

if (insert in the middle) then
	do some command 
else if (insert in the beginning) then
	do some other command
else if (insert in the end) then
	do yet another command
endif

So basically, it's not a showstopper, the other 2 mechanisms of
extraction provide sufficient machinery, the only consideration here
is achieving consistency and completeness by adding what I consider
a natural extension.  

Thanks

Igor