Extending a tuple

4 Messages Forum Options Options
Embed this topic
Permalink
Peter Horan
Extending a tuple
Reply Threaded MoreMore options
Print post
Permalink
I wrote the following code:
     symbols: TUPLE [STRING_8] is
             -- Return a tuple of symbols, read from the command line
        local
             i: INTEGER
        once
             create Result
             from
                 i := 1
             until
                 i > argument_count
             loop
                 Result.put_reference(argument (i), i)
                 i := i + 1
             end
        end

`put_reference' fails a `valid_index' precondition when i = 2. I  
believe this is because ["x", "y"] conforms to ["x"] and not the other  
way around.

How should I write this instead?
--
Peter Horan                     Faculty of Science and Technology
peter@...             Deakin University
+61-4-0831 2116 (Voice)         Geelong, Victoria 3217, AUSTRALIA
+61-3-5227 2028 (FAX)           http://www.eit.deakin.edu.au/~peter

-- The Eiffel guarantee: From specification to implementation
-- (http://www.cetus-links.org/oo_eiffel.html)


------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/eiffel_software/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/eiffel_software/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:eiffel_software-digest@...
    mailto:eiffel_software-fullfeatured@...

<*> To unsubscribe from this group, send an email to:
    eiffel_software-unsubscribe@...

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/

Peter Horan
Re: Extending a tuple
Reply Threaded MoreMore options
Print post
Permalink
Peter Horan wrote:

> I wrote the following code:
>      symbols: TUPLE [STRING_8] is
>              -- Return a tuple of symbols, read from the command line
>         local
>              i: INTEGER
>         once
>              create Result
>              from
>                  i := 1
>              until
>                  i > argument_count
>              loop
>                  Result.put_reference(argument (i), i)
>                  i := i + 1
>              end
>         end
>
> `put_reference' fails a `valid_index' precondition when i = 2. I  
> believe this is because ["x", "y"] conforms to ["x"] and not the  
> other  way around.
>
> How should I write this instead?

My comment is not right. The reason one string is accepted is that I  
have declared only one string in TUPLE[STRING_8].

How do I declare a TUPLE to allow an arbitrary number of items?
--
Peter Horan             Faculty of Science and Technology
peter@...     Deakin University
+61-4-0831 2116 (Voice) Geelong, Victoria 3217, AUSTRALIA
+61-3-5227 2028 (FAX)   http://www.eit.deakin.edu.au/~peter

-- The Eiffel guarantee: From specification to implementation
-- (http://www.cetus-links.org/oo_eiffel.html)



------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/eiffel_software/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/eiffel_software/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:eiffel_software-digest@...
    mailto:eiffel_software-fullfeatured@...

<*> To unsubscribe from this group, send an email to:
    eiffel_software-unsubscribe@...

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/

Emmanuel Stapf
RE: Extending a tuple
Reply Threaded MoreMore options
Print post
Permalink
> My comment is not right. The reason one string is accepted is that I
> have declared only one string in TUPLE[STRING_8].
>
> How do I declare a TUPLE to allow an arbitrary number of items?

Unfortunately there is no way to specify that in Eiffel code. You should be using
an ARRAY instead since it is more what you would expect. However, you could build
this tuple using INTERNAL but I would not recommend this route if possible.

Regards,
Manu


------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/eiffel_software/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/eiffel_software/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:eiffel_software-digest@...
    mailto:eiffel_software-fullfeatured@...

<*> To unsubscribe from this group, send an email to:
    eiffel_software-unsubscribe@...

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/

------------------------------------------------------------------------  
Eiffel Software
805-685-1006
http://www.eiffel.com       
Customer support: http://support.eiffel.com       
User group: http://groups.eiffel.com/join       
------------------------------------------------------------------------  
Peter Horan
Re: Extending a tuple
Reply Threaded MoreMore options
Print post
Permalink
In reply to this post by Peter Horan
Emmanuel Stapf [ES] wrote:

>> My comment is not right. The reason one string is accepted is that I
>> have declared only one string in TUPLE[STRING_8].
>>
>> How do I declare a TUPLE to allow an arbitrary number of items?
>
> Unfortunately there is no way to specify that in Eiffel code. You  
> should be using
> an ARRAY instead since it is more what you would expect. However,  
> you could build
> this tuple using INTERNAL but I would not recommend this route if possible.

Thank you.

I had reached that conclusion and was thinking about the impact of  
changing to an ARRAY. But, I thought there may have been a way ... :-(.

I had used TUPLE when the arguments were predetermined because of its  
convenient manifest notation - not a good reason, I know - and its  
similarity to notations elsewhere.
--
Peter Horan             Faculty of Science and Technology
peter@...     Deakin University
+61-4-0831 2116 (Voice) Geelong, Victoria 3217, AUSTRALIA
+61-3-5227 2028 (FAX)   http://www.eit.deakin.edu.au/~peter

-- The Eiffel guarantee: From specification to implementation
-- (http://www.cetus-links.org/oo_eiffel.html)



------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/eiffel_software/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/eiffel_software/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:eiffel_software-digest@...
    mailto:eiffel_software-fullfeatured@...

<*> To unsubscribe from this group, send an email to:
    eiffel_software-unsubscribe@...

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/