comp.lang.ada
 help / color / mirror / Atom feed
* Some problems with iterators
@ 2014-08-20 16:48 Victor Porton
  2014-08-21  7:06 ` Egil H H
  0 siblings, 1 reply; 6+ messages in thread
From: Victor Porton @ 2014-08-20 16:48 UTC (permalink / raw)


Why Ada2012 does allow only type name for an iterator in for loops, not an 
iterator object?

I think, it is a design mistake. We should also accept iterator object, 
probably constructed earlier.

Now, it is probably possible to do this by introducing a dummy container 
(used only to initialize my iterator), but this is a hack. We should allow 
creation of iterators without unnecessary containers.

The following does not verify with GCC 4.9.1 (I think it is a compiler bug 
and have reported this bug in GCC Bugzilla):

with Ada.Iterator_Interfaces;

package Test is
   
   type Description_Cursor is new Natural;

   function Has_Element (Position: Description_Cursor) return Boolean;

   package Description_Iterators  is new 
Ada.Iterator_Interfaces(Description_Cursor, Has_Element);

   type Description_Iterator is new Description_Iterators.Forward_Iterator 
with null record;

   overriding function First (Object: Description_Iterator) return 
Description_Cursor;
   overriding function Next (Object: Description_Iterator; Position: 
Description_Cursor) return Description_Cursor;

   type Descriptions_List is tagged limited null record
     with Default_Iterator=>Get_Descriptions_Iterator;

   not overriding function Get_Descriptions_Iterator (List: 
Descriptions_List'Class) return Description_Iterator;

end Test;

However, if I remove 'Class in the declaration of Get_Descriptions_Iterator 
function, it does not work either:

test.ads:19:28: operation can be dispatching in only one type

This may indicate one more design error: I cannot define Default_Iterator of 
a suitable subprogram signature. Or is there any way to work around this 
problem? How to define it? Please show example code.

-- 
Victor Porton - http://portonvictor.org

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Some problems with iterators
  2014-08-20 16:48 Some problems with iterators Victor Porton
@ 2014-08-21  7:06 ` Egil H H
  2014-08-21 16:34   ` Victor Porton
  0 siblings, 1 reply; 6+ messages in thread
From: Egil H H @ 2014-08-21  7:06 UTC (permalink / raw)


On Wednesday, August 20, 2014 6:48:53 PM UTC+2, Victor Porton wrote:
> Why Ada2012 does allow only type name for an iterator in for loops,

Please provide an example, or better yet, an RM reference, I can't find any for-loop that takes a type name for an iterator.

> not an iterator object?

But we can, RM 5.5.2(2/3).

> I think, it is a design mistake. 

Clearly not.

> The following does not verify with GCC 4.9.1 (I think it is a compiler bug 
> and have reported this bug in GCC Bugzilla):

What error do you get? 


I believe the rest of your post was answered in this thread:
https://groups.google.com/forum/?authuser=0#!searchin/comp.lang.ada/porton$20$27class%7Csort:date/comp.lang.ada/J-orbhzFZ-8/kF9YuqKIQNQJ



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Some problems with iterators
  2014-08-21  7:06 ` Egil H H
@ 2014-08-21 16:34   ` Victor Porton
  2014-08-21 16:46     ` Victor Porton
  0 siblings, 1 reply; 6+ messages in thread
From: Victor Porton @ 2014-08-21 16:34 UTC (permalink / raw)


Egil H H wrote:
> On Wednesday, August 20, 2014 6:48:53 PM UTC+2, Victor Porton wrote:
>> Why Ada2012 does allow only type name for an iterator in for loops,
> 
> Please provide an example, or better yet, an RM reference, I can't find
> any for-loop that takes a type name for an iterator.
> 
>> not an iterator object?
> 
> But we can, RM 5.5.2(2/3).

It seems my misreading of RM:

"For the first form of iterator_specification, called a generalized 
iterator, the expected type for the iterator_name is any iterator type."

I understood this as need to supply an iterator type as iterator_name, not a 
value of this type. It seems my misunderstanding.

>> The following does not verify with GCC 4.9.1 (I think it is a compiler
>> bug and have reported this bug in GCC Bugzilla):
> 
> What error do you get?

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62205

test.ads:19:28: Default Iterator must be a primitive of "Descriptions_List"

Also, it seems that GCC 4.9.1 does not support "for ... in ... loop" syntax.

-- 
Victor Porton - http://portonvictor.org

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Some problems with iterators
  2014-08-21 16:34   ` Victor Porton
@ 2014-08-21 16:46     ` Victor Porton
  2014-08-21 23:01       ` Randy Brukardt
  0 siblings, 1 reply; 6+ messages in thread
From: Victor Porton @ 2014-08-21 16:46 UTC (permalink / raw)


Victor Porton wrote:
> Also, it seems that GCC 4.9.1 does not support "for ... in ... loop"
> syntax.

I mean this syntax is unsupported for iterators.

-- 
Victor Porton - http://portonvictor.org

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Some problems with iterators
  2014-08-21 16:46     ` Victor Porton
@ 2014-08-21 23:01       ` Randy Brukardt
  2014-08-22  7:59         ` Egil H H
  0 siblings, 1 reply; 6+ messages in thread
From: Randy Brukardt @ 2014-08-21 23:01 UTC (permalink / raw)


I don't think this is likely (although I can't say for sure because I don't 
know the relationship of GCC 4.9.1 to GNATPro version numbers). ACATS 4.0 
has a number of tests for iterators (thanks to Brad Moore), and all of the 
forms are tested except the new array forms ("for ... of ... loop" for an 
array object). At least some parts of those work on recent versions of 
GNATPro that I've tried (older ones have some issues with corner cases, 
which is likely since they didn't have the ACATS tests to work with).

                                  Randy.

"Victor Porton" <porton@narod.ru> wrote in message 
news:lt57pa$4un$1@speranza.aioe.org...
> Victor Porton wrote:
>> Also, it seems that GCC 4.9.1 does not support "for ... in ... loop"
>> syntax.
>
> I mean this syntax is unsupported for iterators.
>
> -- 
> Victor Porton - http://portonvictor.org 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Some problems with iterators
  2014-08-21 23:01       ` Randy Brukardt
@ 2014-08-22  7:59         ` Egil H H
  0 siblings, 0 replies; 6+ messages in thread
From: Egil H H @ 2014-08-22  7:59 UTC (permalink / raw)


On Friday, August 22, 2014 1:01:42 AM UTC+2, Randy Brukardt wrote:
> I don't think this is likely (although I can't say for sure because I don't 
> know the relationship of GCC 4.9.1 to GNATPro version numbers). 

According to https://people.debian.org/~lbrenta/debian-ada-policy.html#Timeline-of-GNAT-releases
GCC 4.9.1 is roughly equivalent to GNAT GPL 2014, which is roughly equivalent to GNAT Pro 7.2. 
7.2 definitely supports the syntax.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-08-22  7:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-20 16:48 Some problems with iterators Victor Porton
2014-08-21  7:06 ` Egil H H
2014-08-21 16:34   ` Victor Porton
2014-08-21 16:46     ` Victor Porton
2014-08-21 23:01       ` Randy Brukardt
2014-08-22  7:59         ` Egil H H

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox