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 ?

Imagine please a sausage, it has the sausage-meat and the sausage-shell.
Then imagine a slice of that sausage.
This slice again consists of meat and shell, see?
Same with sequences, slice of a sequence has its meat (say, atom) and
shell ({}).   smile

But if without jokes, if you want x[n] to be equal x[n..n],
then you'll need to do {x[n..n]}, if you want a sequence, when x[n]
is an atom.
And now, x[n] may be an atom, but x[n..n] is always sequence.

I think, we have good rules in Euphoria now.

Regards,
Igor Kachan
kinz at peterlink.ru

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

Search



Quick Links

User menu

Not signed in.

Misc Menu