Re: Why equal(x[n], x[n..n])=0 ?

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

Fernando Bauer wrote:
> 
> Hi All,
> 
> I was debugging a function when I noticed that a slice with equal indexes is
> different from an access with one index. x[n] is different from x[n..n] where
> n is a valid index.
> According to the manual, a slice always result in a sequence (also when x[n]
> is an atom). But, in particular, when we have something like x[n..n], the
> result
> is x[n] with the its depth incremented by 1. In other words, the structure of
> the element depends on the access form (subscription or slicing). For me, this
> is a surprising fact. 
> This kind of implementation affects some algorithms, because we have to test
> when the indexes are equal in order to not use slice.
> So, why equal(x[n], x[n..n])=0 ?
> 
Hmmm.
What we currently have is this:
sequence s
  s={1,3,5,7,11}
  s[2..4]={3,5,7}
  s[2..3]={3,5}
  s[2..2]={3}
  s[2..1]={}

and what you seem to be saying is that you are surprised it is not:
s[2..3]={3,5}
  s[2..2]=3
  s[2..1]={}

I think that would cause far more shock and surprise. What algorithms does this
affect anyway?
Of course if you always compare slices with slices, and subscripts with
sunscripts, then no such issue ever arises.

Regards,
Pete

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

Search



Quick Links

User menu

Not signed in.

Misc Menu