Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"Jesus saves...but Gretzky gets the rebound!" -- Daniel Hinojosa (hinojosa@hp-sdd)


devel / comp.lang.misc / Constants and Ada Universal_Integer

SubjectAuthor
* Constants and Ada Universal_IntegerJames Harris
+* Re: Constants and Ada Universal_IntegerDmitry A. Kazakov
|`- Re: Constants and Ada Universal_IntegerJames Harris
`- Re: Constants and Ada Universal_Integerantispam

1
Constants and Ada Universal_Integer

<sjkh7r$v7q$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=985&group=comp.lang.misc#985

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!rocksolid2!news.neodome.net!weretis.net!feeder8.news.weretis.net!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: james.harris.1@gmail.com (James Harris)
Newsgroups: comp.lang.misc
Subject: Constants and Ada Universal_Integer
Date: Wed, 6 Oct 2021 17:00:58 +0100
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <sjkh7r$v7q$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 6 Oct 2021 16:00:59 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="1aeaed5304f3561862820db32c228b40";
logging-data="31994"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ZoFa6sJFoPvf+QuHm4IOlvzqz9eSGr/Q="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:Y9jqZudIsECm9+3UDWq3P0m39bE=
Content-Language: en-GB
X-Mozilla-News-Host: snews://news.eternal-september.org:563
 by: James Harris - Wed, 6 Oct 2021 16:00 UTC

Simple question: What are the differences between Ada's
Universal_Integer and a typical bigint type?

By bigint I mean a signed integer which expands and contracts to be as
wide as needed.

I read a comment that one cannot define an Ada object as being of type
Universal_Integer but I wondered why not. Wouldn't it make sense to have
Ada programs (or programs in another language, for that matter) treat
integer constants and expressions as of type bigint?

One additional point: In an expression which combines a constant (or
constant expression) with a declared object the value of the undeclared
constant expression would be automatically converted. For example, in

x + 4

the undeclared bigint 4 would be automatically converted to the type of
x as long as it was in range.

Would there be any practical problems with treating integer literals in
that way?

--
James Harris

Re: Constants and Ada Universal_Integer

<sjkipm$3ga$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=989&group=comp.lang.misc#989

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!aioe.org!x6YkKUCkj2qHLwbKnVEeag.user.46.165.242.91.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.misc
Subject: Re: Constants and Ada Universal_Integer
Date: Wed, 6 Oct 2021 18:27:36 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sjkipm$3ga$1@gioia.aioe.org>
References: <sjkh7r$v7q$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="3594"; posting-host="x6YkKUCkj2qHLwbKnVEeag.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Dmitry A. Kazakov - Wed, 6 Oct 2021 16:27 UTC

On 2021-10-06 18:00, James Harris wrote:
> Simple question: What are the differences between Ada's
> Universal_Integer and a typical bigint type?

The incoming standard will have bigint package in the standard library.

> By bigint I mean a signed integer which expands and contracts to be as
> wide as needed.
>
> I read a comment that one cannot define an Ada object as being of type
> Universal_Integer but I wondered why not.

The reason was not to burden small targets.

But the main difference is that a universal type is considered a member
of each type hierarchy, e.g. each integer type is a subtype of
Universal_Integer. This is why these are all correct:

A : Array (1..10) of Boolean;
I : Integer := A'Length; -- Universal_Integer becoming Integer
J : Integer_64 := A'Length; -- Universal_Integer becoming Integer_64

> Wouldn't it make sense to have
> Ada programs (or programs in another language, for that matter) treat
> integer constants and expressions as of type bigint?

No, because of above. Bigint is a normal type, so you have to explicitly
convert from and to it.

> One additional point: In an expression which combines a constant (or
> constant expression) with a declared object the value of the undeclared
> constant expression would be automatically converted. For example,  in
>
>   x + 4
>
> the undeclared bigint 4 would be automatically converted to the type of
> x as long as it was in range.

That would require mechanics Ada does not have, namely ad-hoc sub- and
supertypes. The most close thing to that is C++ type conversion operators.

<rant on> IMO, The major problem that prevented C++ from becoming a
great language was templates. Instead of investing into the type system,
e.g. user-defined conversions etc, they buried themselves in the mess.
Ada has a similar problem with generics.
<rant off>

> Would there be any practical problems with treating integer literals in
> that way?

Ada community is very resistant towards OO, or better to say, towards
advanced type systems. They are like Bart and you in these issues.

In any case that would be a huge language change with consequences
extremely difficult to foresee. If there were another language to try
this stuff, Ada could learn from it. Unfortunately, language designers
are busy solving imaginary problems and chasing ghosts of last century.
You know these people... (:-))

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: Constants and Ada Universal_Integer

<sjnpce$neh$1@z-news.wcss.wroc.pl>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1014&group=comp.lang.misc#1014

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!feeder.usenetexpress.com!tr1.eu1.usenetexpress.com!feeder5.feed.usenet.farm!feeder1.feed.usenet.farm!feed.usenet.farm!2.eu.feeder.erje.net!feeder.erje.net!newsfeed.pionier.net.pl!pwr.wroc.pl!news.wcss.wroc.pl!not-for-mail
From: antispam@math.uni.wroc.pl
Newsgroups: comp.lang.misc
Subject: Re: Constants and Ada Universal_Integer
Date: Thu, 7 Oct 2021 21:38:22 +0000 (UTC)
Organization: Politechnika Wroclawska
Lines: 63
Message-ID: <sjnpce$neh$1@z-news.wcss.wroc.pl>
References: <sjkh7r$v7q$1@dont-email.me>
NNTP-Posting-Host: hera.math.uni.wroc.pl
X-Trace: z-news.wcss.wroc.pl 1633642702 24017 156.17.86.1 (7 Oct 2021 21:38:22 GMT)
X-Complaints-To: abuse@news.pwr.wroc.pl
NNTP-Posting-Date: Thu, 7 Oct 2021 21:38:22 +0000 (UTC)
Cancel-Lock: sha1:k3EeoidDuFS4/oVYEDpGeQ+bXZA=
User-Agent: tin/2.4.3-20181224 ("Glen Mhor") (UNIX) (Linux/4.19.0-10-amd64 (x86_64))
 by: antispam@math.uni.wroc.pl - Thu, 7 Oct 2021 21:38 UTC

James Harris <james.harris.1@gmail.com> wrote:
> Simple question: What are the differences between Ada's
> Universal_Integer and a typical bigint type?
>
> By bigint I mean a signed integer which expands and contracts to be as
> wide as needed.
>
> I read a comment that one cannot define an Ada object as being of type
> Universal_Integer but I wondered why not. Wouldn't it make sense to have
> Ada programs (or programs in another language, for that matter) treat
> integer constants and expressions as of type bigint?

For Ada there are problems, mostly due to original constraints on
design. For other languages there is no essential problems.
I program every day in Spad, where type 'Integer' is in fact
bigint type. There is also type 'SingleInteger' which represent
machine sized-integers (due to particulars of implementation
range of 'SingleInteger' is slightly smaller than pure machine
integers).

> One additional point: In an expression which combines a constant (or
> constant expression) with a declared object the value of the undeclared
> constant expression would be automatically converted. For example, in
>
> x + 4
>
> the undeclared bigint 4 would be automatically converted to the type of
> x as long as it was in range.

ATM Spad needs explicit convertion to smaller type.
> Would there be any practical problems with treating integer literals in
> that way?

In general when using integers of differing sizes there is correctness
versus efficiency tradeof. Large types means that there is little
(or no) possibility of overflow. However, when smaller types are
large enough they frequently are much more efficient. Consider
the following Spad function:

f() == max()$SingleInteger + 2

Currently Spad compiler generates code based on result type: if
return type of 'f' is declared as 'Integer' (that is bignum)
Spad compiler generates bignum addition. When return type is
declared as 'SingleInteger', then Spad compiler generates
addition in 'SingleInteger', which will overflow. For this
example Spad rules in fact work resonably well, but in general
it is tricky to decide which type to use (Spad tends to err
on side of correctness and use bignums). In Spad there is
possibilty to manualy choose types, that is you can write:

x +$SingleInteger qconvert(2)@SingleInteger

where '+$SingleInteger' means '+' for type 'SingleInteger' and
'qconvert(2)@SingleInteger' effectively changes type of constant.
Note that Spad in used mostly for mathematical computation
and there is tendecy for users to choose values close to
type limits. So, there is quite nontrivial risk that
addition or multiplication in fixed width type will overflow.

--
Waldek Hebisch

Re: Constants and Ada Universal_Integer

<su8re4$u44$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1783&group=comp.lang.misc#1783

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: james.harris.1@gmail.com (James Harris)
Newsgroups: comp.lang.misc
Subject: Re: Constants and Ada Universal_Integer
Date: Sat, 12 Feb 2022 17:40:20 +0000
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <su8re4$u44$1@dont-email.me>
References: <sjkh7r$v7q$1@dont-email.me> <sjkipm$3ga$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 12 Feb 2022 17:40:20 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="b36d7cd7a2226d888bf6546c38de8278";
logging-data="30852"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19UpR/sF126qzAjm9aVf2ew7JVPZa8u+4k="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:k18k4Plf5Nb3DVyXDqSmb+Sh2tQ=
In-Reply-To: <sjkipm$3ga$1@gioia.aioe.org>
Content-Language: en-GB
 by: James Harris - Sat, 12 Feb 2022 17:40 UTC

On 06/10/2021 17:27, Dmitry A. Kazakov wrote:
> On 2021-10-06 18:00, James Harris wrote:
>> Simple question: What are the differences between Ada's
>> Universal_Integer and a typical bigint type?
>
> The incoming standard will have bigint package in the standard library.
>
>> By bigint I mean a signed integer which expands and contracts to be as
>> wide as needed.
>>
>> I read a comment that one cannot define an Ada object as being of type
>> Universal_Integer but I wondered why not.
>
> The reason was not to burden small targets.

I don't see the problem. Couldn't expressions involving /only/ literals
be carried out at compile time?

Similarly, couldn't compile-time expressions (including literals) which
are combined with an identifier be imkplicitly 'converted' at compile
time into the type of the identifier?

If all the BigInt stuff can be carried out at compile time I cannot see
how it would be a burden to small targets.

>
> But the main difference is that a universal type is considered a member
> of each type hierarchy, e.g. each integer type is a subtype of
> Universal_Integer. This is why these are all correct:
>
>    A : Array (1..10) of Boolean;
>    I : Integer    := A'Length; -- Universal_Integer becoming Integer
>    J : Integer_64 := A'Length; -- Universal_Integer becoming Integer_64
>
>> Wouldn't it make sense to have Ada programs (or programs in another
>> language, for that matter) treat integer constants and expressions as
>> of type bigint?
>
> No, because of above. Bigint is a normal type, so you have to explicitly
> convert from and to it.

I am thinking to specify (in future) that all integer literals are of
BigInt type but to have them combinable with identifiers by implicit
compile-time conversions. For example,

int A := 90 ;90 would be of type BigInt but converted to type int

I guess you wouldn't much care for that. :-)

--
James Harris

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor