{BOUNDED_QUEUE}..linear_representation

8 messages Options
Embed this post
Permalink
technoben59

{BOUNDED_QUEUE}..linear_representation

Reply Threaded More More options
Print post
Permalink

Hi. Perhaphs I say a big asinine, but it seems that the source code of
{BOUNDED_QUEUE}.linear_representation is wrong. It says:

linear_representation: ARRAYED_LIST [G]
       -- Representation as a linear structure
       -- (in the original insertion order)
    local
        i: INTEGER_32
    do
       create Result.make (count)
       if out_index > in_index then
          from i := out_index
          until i >= fl.count
          loop
             Result.extend (fl.item (i))
             i := i + 1
          end
          from
>>>         i := 1
          until
             i >= in_index
          loop
             Result.extend (fl.item (i))
             i := i + 1
          end
    else
       from i := out_index
       until i >= in_index
       loop
          Result.extend (fl.item (i))
          i := i + 1
       end
    end
end

fl is an array, so it shoud start at 0, not at 1 (>>>). Am I wrong?

If it's not wrong, I don't understand very well the usage of this
function. Bye.



[Non-text portions of this message have been removed]

dlebansais

Re: {BOUNDED_QUEUE}..linear_representation

Reply Threaded More More options
Print post
Permalink
>
> fl is an array, so it shoud start at 0, not at 1 (>>>). Am I wrong?
>
> If it's not wrong, I don't understand very well the usage of this
> function. Bye.
>

Arrays start at 1 in EiffelStudio. At least, manifest arrays do as well as lists, and strings if my memory is correct.

I hate it every day but that's another story.

Regards,
David Le Bansais.


rfo

RE: Re: {BOUNDED_QUEUE}..linear_representation

Reply Threaded More More options
Print post
Permalink
In reply to this post by technoben59
The default lower bound for ARRAYs (and their friends) is 1 in Eiffel
(not EiffelStudio per se).
There are plenty of discussions on the topic and we won't start a new
one here.

The trick is to remember what language you're using - Eiffel, English,
French, etc (for starting a count with 1), or C/C++/java/assembler (for
starting a count with 0).  Sorry for the thinly disguised editorial
content.

You can create ARRAYs with 0 as the lower bound if you wish but resist
the temptation unless it's absolutely necessary (e.g. when interfacing
with those other languages).  There is a drawback to that approach in
that a lot bounds calculations will be done for no benefit (other than
of course to get indices correct, enforce contracts, make better
software, that sort of stuff).  It might be an interesting excersize to
learn more about Eiffel by creating a descendent of ARRAY that _always_
has a lower bound of 0.  I did this with my AEL_DS_RAW_ARRAY class
(you're welcome to it, but it's not exactly rocket surgery).

Don't try to make Eiffel into java or vice versa.  They are different
for a reason and each has its plusses (or plusplusses) and minuses.  Use
each language as it's intended and you'll be happier in the long run.
When in Rome, blah blah blah.

     R

==================================================
Roger F. Osmond


> -------- Original Message --------
> Subject: [eiffel_software] Re: {BOUNDED_QUEUE}..linear_representation
> From: "David" <[hidden email]>
> Date: Fri, October 16, 2009 6:57 pm
> To: [hidden email]
> >
> > fl is an array, so it shoud start at 0, not at 1 (>>>). Am I wrong?
> >
> > If it's not wrong, I don't understand very well the usage of this
> > function. Bye.
> >
> Arrays start at 1 in EiffelStudio. At least, manifest arrays do as well as lists, and strings if my memory is correct.
> I hate it every day but that's another story.
> Regards,
> David Le Bansais.

technoben59

Re: {BOUNDED_QUEUE}.linear_representation

Reply Threaded More More options
Print post
Permalink
Ok, say that arrays start at 'min' (can be what you want, I think we cannot say that Eiffel's arrays have a default start at zero or one. I said zero because at debugging they're displayed starting at zero).

What I would say is that function {BOUNDED_QUEUE}.linear_representation seems wrong. It runs on 'fl' (an array starting at ... zero) and,

        if out_index > in_index then

check first the final section of array and then the starting section, but starting at 1 (not at 0, like other (right) functions as 'has' do), so it skips the first element. Don't you agree?


--- In [hidden email], <rfo@...> wrote:

>
> The default lower bound for ARRAYs (and their friends) is 1 in Eiffel
> (not EiffelStudio per se).
>
> ==================================================
> Roger F. Osmond
>
>
> > -------- Original Message --------
> > Subject: [eiffel_software] Re: {BOUNDED_QUEUE}..linear_representation
> > From: "David" <dlebansais@...>
> > Date: Fri, October 16, 2009 6:57 pm
> > To: [hidden email]
> > >
> > > fl is an array, so it shoud start at 0, not at 1 (>>>). Am I wrong?
> > >
> > > If it's not wrong, I don't understand very well the usage of this
> > > function. Bye.
> > >
> > Arrays start at 1 in EiffelStudio. At least, manifest arrays do as well as lists, and strings if my memory is correct.
> > I hate it every day but that's another story.
> > Regards,
> > David Le Bansais.
>

--- In [hidden email], "Paolo" <technoben59@...> wrote:

>
>
> Hi. Perhaphs I say a big asinine, but it seems that the source code of
> {BOUNDED_QUEUE}.linear_representation is wrong. It says:
>
> linear_representation: ARRAYED_LIST [G]
>        -- Representation as a linear structure
>        -- (in the original insertion order)
>     local
>         i: INTEGER_32
>     do
>        create Result.make (count)
>        if out_index > in_index then
>           from i := out_index
>           until i >= fl.count
>           loop
>              Result.extend (fl.item (i))
>              i := i + 1
>           end
>           from
> >>>         i := 1
>           until
>              i >= in_index
>           loop
>              Result.extend (fl.item (i))
>              i := i + 1
>           end
>     else
>        from i := out_index
>        until i >= in_index
>        loop
>           Result.extend (fl.item (i))
>           i := i + 1
>        end
>     end
> end
>
> fl is an array, so it shoud start at 0, not at 1 (>>>). Am I wrong?
>
> If it's not wrong, I don't understand very well the usage of this
> function. Bye.
>


Avid Gamer

remembering to count from 1 was: {BOUNDED_QUEUE}..linear_representation

Reply Threaded More More options
Print post
Permalink
In reply to this post by rfo

>
> The default lower bound for ARRAYs (and their friends) is 1
> in Eiffel(not EiffelStudio per se).
> There are plenty of discussions on the topic and we won't
> start a new one here.
>
> The trick is to remember what language you're using -
> Eiffel, English, French, etc (for starting a count with 1),
> or C/C++/java/assembler (for starting a count with 0).
> Sorry for the thinly disguised editorial content.
>
>
> Don't try to make Eiffel into java or vice versa.
> They are different
> for a reason and each has its plusses (or plusplusses)
> and minuses.  Use each language as it's intended and
> you'll be happier in the long run.


Well said.  I like your way of remembering that Eiffel counts from 1, too.

Java is lousy at user interfaces.  It became hugely popular as a server side language for people transitioning away from assembler (that is, C++).  It has the advantage of ubiquity and copious documentation.

Eiffel is great at non-web user interfaces, rapid prototyping, strongly typed applications.  The multiple inheritance is so well done, it's painful to do without it.


A friend of mine made up a joke back in the 80's as he was learning C++:  
"Why isn't there any garbage collection in C++?"  
"Because if there were, there wouldn't be anything left."







carl94706

Re: {BOUNDED_QUEUE}.linear_representation

Reply Threaded More More options
Print post
Permalink
In reply to this post by technoben59
Yes,

I do agree it looks like a bug. It produced incorrect results when I tried the code on my machine.

When you don't use the upper and lower features, you get burned...

Carl


--- In [hidden email], "Paolo" <technoben59@...> wrote:

>
> Ok, say that arrays start at 'min' (can be what you want, I think we cannot say that Eiffel's arrays have a default start at zero or one. I said zero because at debugging they're displayed starting at zero).
>
> What I would say is that function {BOUNDED_QUEUE}.linear_representation seems wrong. It runs on 'fl' (an array starting at ... zero) and,
>
> if out_index > in_index then
>
> check first the final section of array and then the starting section, but starting at 1 (not at 0, like other (right) functions as 'has' do), so it skips the first element. Don't you agree?
>
>
> --- In [hidden email], <rfo@> wrote:
> >
> > The default lower bound for ARRAYs (and their friends) is 1 in Eiffel
> > (not EiffelStudio per se).
> >
> > ==================================================
> > Roger F. Osmond
> >
> >
> > > -------- Original Message --------
> > > Subject: [eiffel_software] Re: {BOUNDED_QUEUE}..linear_representation
> > > From: "David" <dlebansais@>
> > > Date: Fri, October 16, 2009 6:57 pm
> > > To: [hidden email]
> > > >
> > > > fl is an array, so it shoud start at 0, not at 1 (>>>). Am I wrong?
> > > >
> > > > If it's not wrong, I don't understand very well the usage of this
> > > > function. Bye.
> > > >
> > > Arrays start at 1 in EiffelStudio. At least, manifest arrays do as well as lists, and strings if my memory is correct.
> > > I hate it every day but that's another story.
> > > Regards,
> > > David Le Bansais.
> >
>
> --- In [hidden email], "Paolo" <technoben59@> wrote:
> >
> >
> > Hi. Perhaphs I say a big asinine, but it seems that the source code of
> > {BOUNDED_QUEUE}.linear_representation is wrong. It says:
> >
> > linear_representation: ARRAYED_LIST [G]
> >        -- Representation as a linear structure
> >        -- (in the original insertion order)
> >     local
> >         i: INTEGER_32
> >     do
> >        create Result.make (count)
> >        if out_index > in_index then
> >           from i := out_index
> >           until i >= fl.count
> >           loop
> >              Result.extend (fl.item (i))
> >              i := i + 1
> >           end
> >           from
> > >>>         i := 1
> >           until
> >              i >= in_index
> >           loop
> >              Result.extend (fl.item (i))
> >              i := i + 1
> >           end
> >     else
> >        from i := out_index
> >        until i >= in_index
> >        loop
> >           Result.extend (fl.item (i))
> >           i := i + 1
> >        end
> >     end
> > end
> >
> > fl is an array, so it shoud start at 0, not at 1 (>>>). Am I wrong?
> >
> > If it's not wrong, I don't understand very well the usage of this
> > function. Bye.
> >
>


Chris Saunders-4

Re: Re: {BOUNDED_QUEUE}.linear_representation

Reply Threaded More More options
Print post
Permalink
Using `lower' and `upper' whenever possible on arrays is good advice.  It is
only manifest arrays that can be counted on to begin with one if it is used
as originally presented.  I have never attempted to do so but I think that
even manifest arrays could be resized or have `upper' or `lower' altered.

Regards
Chris Saunders

----- Original Message -----
From: carl94706
To: [hidden email]
Sent: Sunday, October 18, 2009 4:17 PM
Subject: [eiffel_software] Re: {BOUNDED_QUEUE}.linear_representation


  Yes,

I do agree it looks like a bug. It produced incorrect results when I tried
the code on my machine.

When you don't use the upper and lower features, you get burned...

Carl

--- In [hidden email], "Paolo" <technoben59@...> wrote:

>
> Ok, say that arrays start at 'min' (can be what you want, I think we
> cannot say that Eiffel's arrays have a default start at zero or one. I
> said zero because at debugging they're displayed starting at zero).
>
> What I would say is that function {BOUNDED_QUEUE}.linear_representation
> seems wrong. It runs on 'fl' (an array starting at ... zero) and,
>
> if out_index > in_index then
>
> check first the final section of array and then the starting section, but
> starting at 1 (not at 0, like other (right) functions as 'has' do), so it
> skips the first element. Don't you agree?
>
>
> --- In [hidden email], <rfo@> wrote:
> >
> > The default lower bound for ARRAYs (and their friends) is 1 in Eiffel
> > (not EiffelStudio per se).
> >
> > ==================================================
> > Roger F. Osmond
> >
> >
> > > -------- Original Message --------
> > > Subject: [eiffel_software] Re: {BOUNDED_QUEUE}..linear_representation
> > > From: "David" <dlebansais@>
> > > Date: Fri, October 16, 2009 6:57 pm
> > > To: [hidden email]
> > > >
> > > > fl is an array, so it shoud start at 0, not at 1 (>>>). Am I wrong?
> > > >
> > > > If it's not wrong, I don't understand very well the usage of this
> > > > function. Bye.
> > > >
> > > Arrays start at 1 in EiffelStudio. At least, manifest arrays do as
> > > well as lists, and strings if my memory is correct.
> > > I hate it every day but that's another story.
> > > Regards,
> > > David Le Bansais.
> >
>
> --- In [hidden email], "Paolo" <technoben59@> wrote:
> >
> >
> > Hi. Perhaphs I say a big asinine, but it seems that the source code of
> > {BOUNDED_QUEUE}.linear_representation is wrong. It says:
> >
> > linear_representation: ARRAYED_LIST [G]
> > -- Representation as a linear structure
> > -- (in the original insertion order)
> > local
> > i: INTEGER_32
> > do
> > create Result.make (count)
> > if out_index > in_index then
> > from i := out_index
> > until i >= fl.count
> > loop
> > Result.extend (fl.item (i))
> > i := i + 1
> > end
> > from
> > >>> i := 1
> > until
> > i >= in_index
> > loop
> > Result.extend (fl.item (i))
> > i := i + 1
> > end
> > else
> > from i := out_index
> > until i >= in_index
> > loop
> > Result.extend (fl.item (i))
> > i := i + 1
> > end
> > end
> > end
> >
> > fl is an array, so it shoud start at 0, not at 1 (>>>). Am I wrong?
> >
> > If it's not wrong, I don't understand very well the usage of this
> > function. Bye.
> >
>


 

Emmanuel Stapf

RE: {BOUNDED_QUEUE}..linear_representation

Reply Threaded More More options
Print post
Permalink
In reply to this post by technoben59
> fl is an array, so it shoud start at 0, not at 1 (>>>). Am I wrong?

It has nothing to do with the fact it is an ARRAY but you are right it should be
0. The fix will be included in the 6.5 release.

Thanks,
Manu

------------------------------------------------------------------------  
Eiffel Software
805-685-1006
http://www.eiffel.com       
Customer support: http://support.eiffel.com       
User group: http://groups.eiffel.com/join       
------------------------------------------------------------------------