Live data from Hacker News

Ada is not just another programming language (1986)

sci-hub.se

1–10 of 68 posts

Re: Ada is not just another programming language (1986)

#6
post #4

I like how in ada you can specify custom range integers

I've always wondered - does Ada track or enforce these ranges?

Like, if I have a variable `i` in range 0...10 and write the Ada equivalent of `i++`, does Ada know that from there on out `i` is in range 1...11? Something like TypeScript's type narrowing?

Re: Ada is not just another programming language (1986)

#7
post #6
post #4

I like how in ada you can specify custom range integers

I've always wondered - does Ada track or enforce these ranges? Like, if I have a variable `i` in range 0...10 and write the Ada equivalent of `i++`, does Ada know that from there on out `i` is in range 1...11? Something like TypeScript's type narrowing?

Yes, it's enforced by any _runtime_ operation. See: https://www.adaic.org/resources/add_content/standards/05rm/h...

Re: Ada is not just another programming language (1986)

#8
post #6
post #4

I like how in ada you can specify custom range integers

I've always wondered - does Ada track or enforce these ranges? Like, if I have a variable `i` in range 0...10 and write the Ada equivalent of `i++`, does Ada know that from there on out `i` is in range 1...11? Something like TypeScript's type narrowing?

The range wouldn’t change in Ada. The type for a variable is fixed at compile time. It will ensure (at runtime and partially at compile time) that the value doesn’t go outside the range, though.

Re: Ada is not just another programming language (1986)

#9
post #6
post #4

I like how in ada you can specify custom range integers

I've always wondered - does Ada track or enforce these ranges? Like, if I have a variable `i` in range 0...10 and write the Ada equivalent of `i++`, does Ada know that from there on out `i` is in range 1...11? Something like TypeScript's type narrowing?

Usually with runtime checks, but it can also in some situations be done statically, such as with SPARK.

Re: Ada is not just another programming language (1986)

#10
post #4

I like how in ada you can specify custom range integers

Pascal had subrange types before Ada, not only for integers but characters too.

    var day : 1 .. 31;
        letter : 'A' .. 'Z';
And you could specify ranges on array subscripts as well:

    var weight : array[-5 .. 5] of integer;
Post reply on HN