From: Shark8 <onewingedshark@gmail.com>
Subject: Re: Dynamic_Predicate with a generic
Date: Tue, 30 Oct 2012 21:31:26 -0700 (PDT)
Date: 2012-10-30T21:31:26-07:00 [thread overview]
Message-ID: <8cb762ea-3010-4351-b5d6-573b4299c95f@googlegroups.com> (raw)
In-Reply-To: <CCB65270.20246%yaldnif.w@blueyonder.co.uk>
> >
> > ==============Error messages for source file: prime_numbers.ads
> > 20. with Dynamic_Predicate => is_prime(prime_number);
> > |
> >>>> invalid use of subtype mark in expression or call
>
> What am I missing?
Maybe nothing, I recently found two bugs one where
declare
item : a_type := ...;
begin
Operation( New a_type'( item) );
end
gave results you would expect from using 'unchecked_access.
and another where LRM 6.5 isn't implemented (Aliased extended returns).
I put the package into the declaration area of a procedure and it compiled fine.
generic
type integral is range <>;
type unsigned_integral is mod <>;
package prime_numbers with Elaborate_Body is
subtype nat_integral is integral range 0 .. integral'Last;
subtype pos_integral is integral range 1 .. integral'Last;
-- returns True iff nr is a prime number
function is_prime (nr : integral) return Boolean;
subtype prime_number is integral
with Dynamic_Predicate => is_prime(prime_number);
end prime_numbers;
package body prime_numbers is
function is_prime (nr : integral) return Boolean is
begin
Return Result : Boolean := Integer(nr) in positive do
if Result then
case pos_integral(nr) is
when 1 | 2 | 3 => null;
when Others =>
declare
subtype Mod_Search is integral range 2..nr-2;
begin
for Index in mod_search loop
if nr mod Index = 0 then
Result := False;
return;
end if;
end loop;
end;
end case;
end if;
end return;
end is_prime;
end prime_numbers;
Type mod_13 is mod 13;
Package P is new Prime_numbers( integral => Integer, unsigned_integral => mod_13);
prev parent reply other threads:[~2012-10-31 4:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-31 3:58 Dynamic_Predicate with a generic Bill Findlay
2012-10-31 4:31 ` Shark8 [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