comp.lang.ada
 help / color / mirror / Atom feed
* Novice Ada Programmer Stumped By Simple Type Declaration!
@ 2001-10-04 19:19 Darren New
  2001-10-04 19:50 ` Ted Dennison
  0 siblings, 1 reply; 10+ messages in thread
From: Darren New @ 2001-10-04 19:19 UTC (permalink / raw)


Here's the basics of what I have --

I have a generic package called DNew.Unbounded_Array, with a formal
private type being the components of the array. (This is roughly
analogous to Unbounded_String only with non-character components.)

I then have
package URI_pkg is
  type URI is new Unbounded_String;
  package URI_List_Pkg is new DNew.Unbounded_Array(Component_Type =>
URI);
  subtype URI_List is URI_List_Pkg.Unbounded_Array;
  function To_URI(S : String) return URI;


Now, DNew.Unbounded_Array defines a type called Unbounded_Array (of
course), as well as 
procedure Append(X : in out Unbounded_Array; Y : in Component_type);
procedure Append(X : in out Unbounded_Array; Y : in Unbounded_Array);


The problem comes when, in an unrelated package, I have

procedure test1 is
  U : URI := To_URI("http://...");
  UL : URI_List;
begin
  Append(UL, U);
end test1;

It seems no matter what "with" and "use" clauses I use, it can't resolve
the Append to be the appropriate one. GNAT gives all kinds of errors,
none of which make much sense.

test-beep_core_profile_registry_pkg.adb:42:26: no candidate
interpretations match the actuals:
test-beep_core_profile_registry_pkg.adb:42:34: expected private type
"URI" defined at beep-core-uri_pkg.ads:8
test-beep_core_profile_registry_pkg.adb:42:34: found private type
"Unbounded_Array" defined at dnew-util-unbounded_array_pkg.ads:13,
instance at beep-core-uri_pkg.ads:10
test-beep_core_profile_registry_pkg.adb:42:34:   ==> in call to "Append"
at beep
-core-uri_pkg.ads:8(inherited)

I believe it may be expecting the Append from Unbounded_String and
getting confused. 

Any help, from anyone? 

The complete set of sources are available at
http://home.san.rr.com/dnew/beepcore.zip.

Thanks in advance for any advice!

-- 
Darren New 
San Diego, CA, USA (PST). Cryptokeys on demand.
                   Who is this Dr. Ibid anyway, 
                  and how does he know so much?



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

* Re: Novice Ada Programmer Stumped By Simple Type Declaration!
  2001-10-04 19:19 Novice Ada Programmer Stumped By Simple Type Declaration! Darren New
@ 2001-10-04 19:50 ` Ted Dennison
  2001-10-04 21:33   ` Darren New
  2001-10-05  4:32   ` Robert Dewar
  0 siblings, 2 replies; 10+ messages in thread
From: Ted Dennison @ 2001-10-04 19:50 UTC (permalink / raw)


In article <3BBCB63C.96E484EA@san.rr.com>, Darren New says...
>It seems no matter what "with" and "use" clauses I use, it can't resolve
>the Append to be the appropriate one. GNAT gives all kinds of errors,
>none of which make much sense.

A good first step in any such problem is to get rid of all use clauses and try
to resolve things with full named notation. (I'd also claim that's a good first
step in *any* situation, but it really is true here :-)  ).

>package URI_pkg is
>  package URI_List_Pkg is new DNew.Unbounded_Array(Component_Type =>
>URI);
..
>Now, DNew.Unbounded_Array defines a type called Unbounded_Array (of
>course), as well as 
>procedure Append(X : in out Unbounded_Array; Y : in Component_type);
>procedure Append(X : in out Unbounded_Array; Y : in Unbounded_Array);
>
>
>The problem comes when, in an unrelated package, I have
>
>procedure test1 is
>  U : URI := To_URI("http://...");
>  UL : URI_List;
>begin
>  Append(UL, U);
>end test1;

It looks like you should be calling URI_Pkg.URI_List_Pkg.Append. But from the
message you gave, I'm guessing it found it but couldn't resolve the overload. It
could be that your compiler (Gnat?) was getting confused because you had two
Unbounded_Array's defined in its scope: One a package, and the other a subtype.
You'd think it should be able to sort that out, but I've seen other situations
where Gnat (3.13p) gets horribly confused by similarly named things. I could
never narrow the problem down enough to satify the report@gnat.com gods, but
rest asured the problem is in there.

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html

No trees were killed in the sending of this message. 
However a large number of electrons were terribly inconvenienced.



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

* Re: Novice Ada Programmer Stumped By Simple Type Declaration!
  2001-10-04 19:50 ` Ted Dennison
@ 2001-10-04 21:33   ` Darren New
  2001-10-05 15:27     ` Ted Dennison
  2001-10-06  8:56     ` Simon Wright
  2001-10-05  4:32   ` Robert Dewar
  1 sibling, 2 replies; 10+ messages in thread
From: Darren New @ 2001-10-04 21:33 UTC (permalink / raw)


Ted Dennison wrote:
> 
> In article <3BBCB63C.96E484EA@san.rr.com>, Darren New says...
> >It seems no matter what "with" and "use" clauses I use, it can't resolve
> >the Append to be the appropriate one. GNAT gives all kinds of errors,
> >none of which make much sense.
> 
> A good first step in any such problem is to get rid of all use clauses and try
> to resolve things with full named notation. (I'd also claim that's a good first
> step in *any* situation, but it really is true here :-)  ).

Did that. Couldn't figure it out.

> It looks like you should be calling URI_Pkg.URI_List_Pkg.Append.

Oh! Duh! It's not URI_Pkg.Append. It's URI_Pkg.URI_List_Pkg.Append.

Adding "use URI_Pkg.URI_List_Pkg" fixes it.

(Incidentally, this is for the unit-test code for a
first-one-to-throw-away project, while I'm learning Ada, so the over-use
of "use" isn't as bad as it might be.)


Thanks! I can't believe I spent two days trying to figure that one out.
:-)

-- 
Darren New 
San Diego, CA, USA (PST). Cryptokeys on demand.
                   Who is this Dr. Ibid anyway, 
                  and how does he know so much?



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

* Re: Novice Ada Programmer Stumped By Simple Type Declaration!
  2001-10-04 19:50 ` Ted Dennison
  2001-10-04 21:33   ` Darren New
@ 2001-10-05  4:32   ` Robert Dewar
  2001-10-05 15:19     ` Ted Dennison
  1 sibling, 1 reply; 10+ messages in thread
From: Robert Dewar @ 2001-10-05  4:32 UTC (permalink / raw)


Ted Dennison<dennison@telepath.com> wrote in message news:<V33v7.16265$ev2.26335@www.newsranger.com>...
> A good first step in any such problem is to get rid of all use clauses and try
> to resolve things with full named notation. (I'd also claim that's a good first
> step in *any* situation, but it really is true here :-) 

I disagree, I think this is relatively unhelpful advice here.
> 
> It looks like you should be calling URI_Pkg.URI_List_Pkg.Append. But from the
> message you gave, I'm guessing it found it but couldn't resolve the overload. It
> could be that your compiler (Gnat?) was getting confused because you had two
> Unbounded_Array's defined in its scope: 


The compiler is not "confused", it merely follows the rules
of Ada, you really should not imply that somehow the
processing of Ada text has some kind of random behavior
depending on whether the compiler gets confused or not.
If you are confused, then that's one thing, but it does
not help to suggest that this confusion is part of the
language :-)

For the trivial solution to the problem, see the next
posted message!



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

* Re: Novice Ada Programmer Stumped By Simple Type Declaration!
  2001-10-05  4:32   ` Robert Dewar
@ 2001-10-05 15:19     ` Ted Dennison
  2001-10-05 16:30       ` Darren New
  0 siblings, 1 reply; 10+ messages in thread
From: Ted Dennison @ 2001-10-05 15:19 UTC (permalink / raw)


In article <5ee5b646.0110042032.57d94ad8@posting.google.com>, Robert Dewar
says...
>
>The compiler is not "confused", it merely follows the rules
>of Ada, you really should not imply that somehow the

Well, since he was indeed not calling the correct routine, that is true. 

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html

No trees were killed in the sending of this message. 
However a large number of electrons were terribly inconvenienced.



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

* Re: Novice Ada Programmer Stumped By Simple Type Declaration!
  2001-10-04 21:33   ` Darren New
@ 2001-10-05 15:27     ` Ted Dennison
  2001-10-06  8:56     ` Simon Wright
  1 sibling, 0 replies; 10+ messages in thread
From: Ted Dennison @ 2001-10-05 15:27 UTC (permalink / raw)


In article <3BBCD596.AF223388@san.rr.com>, Darren New says...
>
>Ted Dennison wrote:
>> 
>> It looks like you should be calling URI_Pkg.URI_List_Pkg.Append.
>
>Oh! Duh! It's not URI_Pkg.Append. It's URI_Pkg.URI_List_Pkg.Append.

Once I figured out how to deal with routines in generic packages, it did become
obvious. But at first I had no end of trouble with it, so don't feel bad about
it.

>
>Adding "use URI_Pkg.URI_List_Pkg" fixes it.

Right. Once you figure out the exact name of the routine you *should* be
calling, then its (arguably) OK to put in the proper use to get access to it.
The problem people get into with uses is that they use them as a crutch so that
they never have to know or think about where stuff is comming from.

>(Incidentally, this is for the unit-test code for a
>first-one-to-throw-away project, while I'm learning Ada, so the over-use
>of "use" isn't as bad as it might be.)

Even for those, I don't do "use"s. 8-)

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html

No trees were killed in the sending of this message. 
However a large number of electrons were terribly inconvenienced.



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

* Re: Novice Ada Programmer Stumped By Simple Type Declaration!
  2001-10-05 15:19     ` Ted Dennison
@ 2001-10-05 16:30       ` Darren New
  0 siblings, 0 replies; 10+ messages in thread
From: Darren New @ 2001-10-05 16:30 UTC (permalink / raw)


> >The compiler is not "confused", it merely follows the rules
> >of Ada, you really should not imply that somehow the
> 
> Well, since he was indeed not calling the correct routine, that is true.

It's not that I was not calling the right routine, as much as it was I
had forgotten the right routine was in a nested package. The *real*
problem is that I had other, overloaded functions with limilar argument
types, so the error messages were unusually unhelpful. They were
pointing me at a completely unrelated routine that *was* in scope, and
telling me I had the wrong argument types.

This is why I'm doing this project - to run into all these kinds of
problems before there's any expectation from anyone that I already know
what I'm doing. ;-)

-- 
Darren New 
San Diego, CA, USA (PST). Cryptokeys on demand.
                   Who is this Dr. Ibid anyway, 
                  and how does he know so much?



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

* Re: Novice Ada Programmer Stumped By Simple Type Declaration!
  2001-10-04 21:33   ` Darren New
  2001-10-05 15:27     ` Ted Dennison
@ 2001-10-06  8:56     ` Simon Wright
  2001-10-07 17:07       ` Darren New
  1 sibling, 1 reply; 10+ messages in thread
From: Simon Wright @ 2001-10-06  8:56 UTC (permalink / raw)


Darren New <dnew@san.rr.com> writes:

> (Incidentally, this is for the unit-test code for a
> first-one-to-throw-away project, while I'm learning Ada, so the
> over-use of "use" isn't as bad as it might be.)
> 
> Thanks! I can't believe I spent two days trying to figure that one
> out.

Not to get at you, but you really should look at those two sentences
together! Wouldn't it have been more effective to kill the "use" and
accept the typing?

GNAT will often tell you that it would be able to resolve a reference
if only you put in a particular "use", best to qualify the name
properly IMHO ..

I find myself increasingly happy with using GNAT.IO or Ada.Text_IO or
Ada.Calendar or ... stuff in the standard libraries, which quite often
has been designed to work with "use". But for your own stuff, resist
it.



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

* Re: Novice Ada Programmer Stumped By Simple Type Declaration!
  2001-10-06  8:56     ` Simon Wright
@ 2001-10-07 17:07       ` Darren New
  2001-10-07 20:50         ` Lutz Donnerhacke
  0 siblings, 1 reply; 10+ messages in thread
From: Darren New @ 2001-10-07 17:07 UTC (permalink / raw)


Simon Wright wrote:
> 
> Darren New <dnew@san.rr.com> writes:
> 
> > (Incidentally, this is for the unit-test code for a
> > first-one-to-throw-away project, while I'm learning Ada, so the
> > over-use of "use" isn't as bad as it might be.)
> >
> > Thanks! I can't believe I spent two days trying to figure that one
> > out.
> 
> Not to get at you, but you really should look at those two sentences
> together! Wouldn't it have been more effective to kill the "use" and
> accept the typing?

That's what I'm saying. I tried that also. When I *did* use the
fully-qualified name, I used the wrong one. 

The problem was that I had a nested child package (because it was an
instantiated generic package) that I was forgetting to put on there. The
routine I was trying to use was not in scope. GNAT was suggesting a
different routine, or that my arguments were in the wrong order. It
didn't matter whether I had any "use" or not, since I wasn't using the
package I was trying to reference anyway. 

It was just one of those "the first time you do this, it'll take a day
to figure out why you're getting an error."  

Kind of like in C when you use an uninitialized pointer, and when you
put in printf's to see why it's dumping core, it stops dumping core. You
can spend days on that the first time too. :-)

> GNAT will often tell you that it would be able to resolve a reference
> if only you put in a particular "use", best to qualify the name
> properly IMHO ..

The problem is when you start having packages like
package Beep.Core.Profiles.Instantiations.Buffers, and you get calls
like
 
Beep.Core.Profile.Instantiations.Buffer.Queue(Beep.Core.Profiles.Instantiations.Frame_Buffer,
Beep.Core.Control.In_Buffer.Next_Frame.all);

I think a couple of "use" clauses there would help. Or a less
heirarchical package mechanism or something.
 
-- 
Darren New 
San Diego, CA, USA (PST). Cryptokeys on demand.
                   Who is this Dr. Ibid anyway, 
                  and how does he know so much?



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

* Re: Novice Ada Programmer Stumped By Simple Type Declaration!
  2001-10-07 17:07       ` Darren New
@ 2001-10-07 20:50         ` Lutz Donnerhacke
  0 siblings, 0 replies; 10+ messages in thread
From: Lutz Donnerhacke @ 2001-10-07 20:50 UTC (permalink / raw)


* Darren New wrote:
>The problem is when you start having packages like
>package Beep.Core.Profiles.Instantiations.Buffers, and you get calls
>like
> 
>Beep.Core.Profile.Instantiations.Buffer.Queue(
>  Beep.Core.Profiles.Instantiations.Frame_Buffer,
>  Beep.Core.Control.In_Buffer.Next_Frame.all);
>
>I think a couple of "use" clauses there would help. Or a less
>heirarchical package mechanism or something.

No need for use anyway:  -- also catch your typing error
  package BCPI renames Beep.Core.Profiles.Instantiations;
  package BCCI renames Beep.Core.Control.In_Buffer;
  
  BCPI.Buffer.Queue (BCPI.Frame_Buffer, BCCI.Next_Frame.all);



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

end of thread, other threads:[~2001-10-07 20:50 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-04 19:19 Novice Ada Programmer Stumped By Simple Type Declaration! Darren New
2001-10-04 19:50 ` Ted Dennison
2001-10-04 21:33   ` Darren New
2001-10-05 15:27     ` Ted Dennison
2001-10-06  8:56     ` Simon Wright
2001-10-07 17:07       ` Darren New
2001-10-07 20:50         ` Lutz Donnerhacke
2001-10-05  4:32   ` Robert Dewar
2001-10-05 15:19     ` Ted Dennison
2001-10-05 16:30       ` Darren New

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