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

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

Derek Parnell wrote:
> 
> Fernando Bauer wrote:
> 
> > > Another way to look at is this ...
> > > 
> > >   s[3 .. 4] is "er"
> > >   s[3 .. 3] is "e"
> > Ok. But why s[3..3] is not 'e'? Why the original 'e' is transformed in "e" ?
> 
> It seems that you are not thinking things through clearly. The character 'e'
> has not been transformed. 
Let me see the dictionary:
transform = "To change markedly the form or appearance of"
change = "To cause to be different".
Now, we have originally an atom 'e' (form A). After slicing we have a sequence
"e" (form B). Clearly, form A != form B (even in computer memory), so slicing
changes the form A to form B, and this is the definition of "transform" above. So
I conclude that that slice transforms 'e' into "e".

> 
> The bucket analogy is an excellent one. 
> 
> If you have a bucket of fruit, and you want to create a NEW bucket of fruit
> using one piece of fruit from the initial one, the syntax to do that is 
> 
>     newBucket = oldBucket[n..n]
> 
> If you have a bucket of fruit, and you want to look at one piece of fruit that
> is in it, the syntax to do that is 
> 
>     theFruit = oldBucket[n]
> 
> As you can see, the syntax you actually use depends on what you want to
> achieve.
> The slice syntax [x..y] gives you a new sequence/container/bucket, and the
> element
> reference syntax [z] gives you one element from a container.
> 
> > Yes. The manual is also very clear about this. However, 
> > the meaning of my question is another:
> > Why does Euphoria (the manual) define slices 
> > like x[n..n] and x[n] differently?
> 
> You misunderstand, it seems.
I dont't think so. Probably my question is not precise. Let me try again:
Why does Euphoria (the manual) define slice x[n..n] different from subscription
x[n]?

> 
>    [n..n] IS a slice, and [n] IS NOT a slice. 
I know this! This is the syntax definition of slice. This is clear in the
manual! My question is: why doesn't the interpreter transform the slice into a
subscript when the indexes are equal?

>    [n..n] IS NOT an element reference, and [n] IS an element reference.
Ok. But why [n..n] can't be an element reference? Why aren't they synonyms?

> 
> > Why is an atom transformed in a sequence by using a slice?
> 
> There is no transformation. If one has a sequence (which a slice always is),
> one can insert an atom into it. The atom is not transformed.
See above why I think we can say that there is a transformation. 

> 
> > An analogy:
> > Suppose you have a set of enumerated objects and the following rules:
> > a)You can hold only one at a time. (subscription)
> 
> Hold the object in what? A container maybe?
For a concrete example, in your hand.

> 
> > b)If you need more objects you can use a container. (slicing)
> > Then, if someone asks you to collect the objects 2 to 4?
> >  - Because the number of objects is 3, you need to use
> > the container (rule 2).
> 
> Why? That is only one option. Another is to hold the VALUES in a set of
> objects.
> 
>     object a,b,c
>     a = bucket[2]
>     b = bucket[3]
>     c = bucket[4]
You can't hold more than either one object or a container in your hand.
(I mean "either a or b" = a xor b)

> 
> This is why I was saying that the way you want to see the data dictates the
> method used to store the data. 
> 
> > Now, if someone asks you to collect the objects 2 to 2?
> >  - Because the number of objects is 1, you *don't* need
> > to use the container, you can catch it directly (rule 1). 
> 
> So you acknowledge this is optional. That is, you can have the single object
> as an entity itself or you can has it as the contents of a container. It's
> your
> choice. So to tell Euphoria which method you have chosen, you use the
> appropriate
> syntax. If you want the just the object use bucket[2], however if you want it
> in a container then use bucket[2..2]. It's your choice.
Ok. But sometimes you want to use slice, and then you have to test the length of
the slice or the values of the indexes. This probably adds lines of code and
processing time.

> 
> > Besides, if you use the container (sequence),you will 
> > have to discard it to catch the object (an unnecessary procedure).
> 
> Why? It depends on what you want to do with it. It's your choice.
Ok. But normally you want to catch (access) the object, or in other words, you
normally want to subscript the sequence (x[n]), which is the discard procedure.

> 
> -- 
> Derek Parnell
> Melbourne, Australia
> Skype name: derek.j.parnell

Regards,
   Fernando

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

Search



Quick Links

User menu

Not signed in.

Misc Menu