Re: Is subscripting a slice useful
- Posted by codepilot Gmail Account <codepilot at gmail.com> Oct 08, 2004
- 546 views
Totally correct, my foot hurts, should be {97,97}. And I dont think I could prove that native is much faster, but would look nicer. On Sat, 09 Oct 2004 00:17:19 +0100, Pete Lomax <petelomax at blueyonder.co.uk> wrote: > > On Fri, 8 Oct 2004 14:26:12 -0700, codepilot Gmail Account > <codepilot at gmail.com> wrote: > > >Right now subscripting a slice is not allowed. > > > >}}} <eucode> > >constant asdf={"asdf","asdf","asdf","asdf"} > >? asdf[1..2][1] > ></eucode> {{{ > >I think that this code should print out {97,97,97,97}. > > I think you just shot yourself in the foot ) > > There is *no* way that asdf[1..2] should return anything other than a > sequence of length 2, and hence a nested subscript of that could not > possibly yield a sequence of length 4. What, in contrast, would you > expect asdf[1..4][1] to print? (Surely something else!) > > This whole idea (which has been extensively discussed before) is so > open to misinterpretation it should definitely NOT be "standard". > Every application needs something different. > > That said, it is not difficult. If you want to extract something from > a complex sequence then I'll happily write a function for you, given a > suitable example. If you wanted {97,97} then: > > }}} <eucode> > constant asdf={"asdf","asdf","asdf","asdf"} > > function subscript(object o, sequence what) > object this > this=what[1] > what=what[2..length(what)] > if sequence(this) then > if length(this)!=2 then ?9/0 end if > for i=this[1] to this[2] do > o[i]=subscript(o[i],what) > end for > return o[this[1]..this[2]] > end if > if length(what) then > return subscript(o[this],what) > end if > return o[this] > end function > > ? subscript(asdf,{{1,2},1}) > </eucode> {{{ > > prints {97,97} > > Let me know if this does not do exactly what you want. > > Regards, > Pete > PS I'd be quite surprised if anyone could prove this was significantly > slower than doing it "native". The cost is entirely in the creation of > the new sequence (aka result); the subscripting/function calls pale > into insignificance. CMIIW, if you can. > > > > >