From: Kenneth Wolcott <kennethwolcott@gmail.com>
Subject: Re: Rosetta Code task Proper divisors fails to compile
Date: Wed, 26 Jul 2023 15:26:28 -0700 (PDT) [thread overview]
Message-ID: <e9fce00e-7fd0-4ce0-a874-acb29d4e0e80n@googlegroups.com> (raw)
In-Reply-To: <u9rtrh$1hutd$1@dont-email.me>
On Wednesday, July 26, 2023 at 12:57:40 PM UTC-7, Jeffrey R.Carter wrote:
> On 2023-07-26 20:30, Kenneth Wolcott wrote:
> >
> > Thank you for your suggestion. Doesn't seem to have any effect.
> Interesting. I get the same results with GNAT 12.
>
> Looking more closely at the code, I think the error, while its msg is
> misleading, is correct. A function that returns a limited type can only return
> an aggregate, a function call, or an object declared by an extended return
> statement. The generic formal object None is none of these.
>
> Changing the generic parameter to a function
>
> with function None return Result_Type;
>
> makes the code correct. You need to change the definition of Empty in
> Proper_Divisors
>
> function Empty return Pos_Arr is (1 .. 0 => <>);
>
> and create a function to supply for the 2nd instantiation
>
> function None return Natural is (0);
> ...
> package Divisor_Count is new Generic_Divisors
> (Result_Type => Natural, None => None, One => Cnt, Add => "+");
>
> and then it compiles and runs.
>
> Another possibility is to make Result_Type simply private, though that is
> slightly less general. That may be how the OP got the code to compile and run.
> It might be that limited was added later because the OP saw that it could be,
> and never tested the change.
Hi Jeff;
Thank you for your reply.
I went with the latter suggestion for my local use.
Ken
prev parent reply other threads:[~2023-07-26 22:26 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-26 4:49 Rosetta Code task Proper divisors fails to compile Kenneth Wolcott
2023-07-26 8:36 ` Jeffrey R.Carter
2023-07-26 18:30 ` Kenneth Wolcott
2023-07-26 19:57 ` Jeffrey R.Carter
2023-07-26 22:26 ` Kenneth Wolcott [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox