Re: Why equal(x[n], x[n..n])=0 ?
- Posted by Fernando Bauer <fmbauer at h?tmail.?om> Sep 26, 2007
- 723 views
Hi Ricardo. Thanks for your reply. Ricardo Forno wrote: > > Hi Fernando. > Maybe the point is that x[1..5] as well as x[3..3] are slices (two indexes > separated > by two periods), while x[5] (a single index) is not a slice. > The simplest case: assume all elements of x are atoms. Then x[i] is an atom, > and x[i..j] is a sequence of atoms. > Assume also that you have this loop (code not tested): > > x = repeat(4, 10) > > for i = 10 to 1 by -1 do > foo(x[1..i]) > end for > > The foo() procedure gets sequences with diminishing length, and processes > them. > It expects it has to deal with a sequence. Yes. For functions expecting a sequence, only the current definition of slice works, and probably this is the cause of that slice definition. But then I ask, why not define a similar but more generic function which accepts object? > But, oh surprise!, when you get to i = 1 (if x[n] where the same as x[n..n], > as you propose), it would get an atom!, and probably fail. > So, foo() should test if its argument is a sequence or an atom before > proceeding. Yes. I think this is a common procedure in all functions that receive objects. > Don't you think this way things would be more complex? For now, I don't know. I think that I'd have to have much more experience with Euphoria to correctly answer this. I'm learning with all of you with these discussions. > > Best regards. > > PD: Hi Fernando. > I am from Buenos Aires, Argentina. I recall you are from Porto Alegre, Brazil, > true? Yes. And I know a few things about you thanks to the Euforum. > I understand enough Portuguese. You can contact me at ricardoforno at > tutopia.com > in Portuguese if you like. > Ah! And I plan to take my holydays in the south of Brazil next January, with > my wife. Maybe we can meet then. Ok. Maybe. Best Regards, Fernando