Re: Simple Pascal question

Liste des Groupes 
Sujet : Re: Simple Pascal question
De : arne (at) *nospam* vajhoej.dk (Arne Vajhøj)
Groupes : comp.os.vms
Date : 04. Aug 2024, 15:51:20
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v8o4h8$2ut3$1@dont-email.me>
References : 1 2 3 4
User-Agent : Mozilla Thunderbird
On 8/4/2024 8:22 AM, Dan Cross wrote:
In article <v8lpj0$ems$1@panix2.panix.com>,
Scott Dorsey <kludge@panix.com> wrote:
In article <v8hn3m$3aviu$1@gwaiyur.mb-net.net>,
Uli Bellgardt  <UliBellgardtsSpamSink@online.de> wrote:
The value 1.5 should be an f_float value as well:
>
$ type zzz.pas
program z(input,output);
>
var
    x : f_float;
>
This seems very strange to me... Pascal isn't supposed to have such
strong typing, is it?  I don't remember ever having to manually coerce
anything.  Or is f_float sufficiently different from a normal float?
 Just to touch on the Pascal point itself, one of that language's
hallmarks is almost excessive rigidity in how it treats types.
Ada is even more strict.

While integer->float conversions are implicit, the opposite is
not.  I think that the general rule is that when a type "widens"
conversion is implicitly ok (so in mathematics, when the
integers are a proper subset of the reals, so every integer is
already a real, and implicit conversion from int to real is
intuitive, even though representations on physical computers
aren't quite so neat for implementation reasons), but when types
narrow, as in when going from real to int, one must exercise
more caution.
Such a restriction is rather common today.
Random example:
$ javac Z.java
Z.java:6: error: incompatible types: possible lossy conversion from double to int
         iv = xv;
              ^
1 error

An old annoyance about Pascal was that the size of an array is
part of it's type, which makes writing functions and procedures
that work across differently sized arrays challenging.
In original Wirth Pascal. Most implementations has solutions.
VMS:
program flex_array(input, output);
procedure dump(a : array[lb..ub:integer] of integer);
var
    i : integer;
begin
    for i := lbound(a) to hbound(a) do begin
         write(' ', a[i]:1);
    end;
    writeln;
end;
var
    a1 : array [1..1] of integer value [ 1: 1 ];
    a2 : array [2..3] of integer value [ 2: 1; 3: 2 ];
    a3 : array [4..6] of integer value [ 4: 1; 5: 2; 6: 3 ];
begin
    dump(a1);
    dump(a2);
    dump(a3);
end.
FPC/Lazarus:
program flex_array(input, output);
procedure dump(a : array of integer);
var
    i : integer;
begin
    for i := low(a) to high(a) do begin
      write(' ', a[i]:1);
    end;
    writeln;
end;
var
    a1 : array [1..1] of integer = ( 1 );
    a2 : array [2..3] of integer = ( 1, 2 );
    a3 : array [4..6] of integer = ( 1, 2, 3 );
begin
    dump(a1);
    dump(a2);
    dump(a3);
end.

Interesting, this has become du jour again in modern languages,
but those tend to provide access to a `slice` type that provides
a window onto the underly array, and implicitly encodes a
length (and usually a "capacity").  This makes working with
arrays in such languages very convenient.
Different people may have different opinions on what is a modern
language.
But a lot of the widely used static typed languages does not
have any problems with arrays of different lengths as they
are treated as objects.
Like:
public class FlexArray {
     private static void dump(int[] a) {
         for(int v : a) {
             System.out.printf(" %d", v);
         }
         System.out.println();
     }
     public static void main(String[] args) throws Exception {
         int[] a1 = { 1 };
         int[] a2 = { 1, 2 };
         int[] a3 = { 1, 2, 3 };
         dump(a1);
         dump(a2);
         dump(a3);
     }
}
Arne

Date Sujet#  Auteur
1 Aug 24 * Simple Pascal question41Arne Vajhøj
2 Aug 24 `* Re: Simple Pascal question40Uli Bellgardt
3 Aug 24  +* Re: Simple Pascal question38Scott Dorsey
3 Aug 24  i+- Re: Simple Pascal question1Arne Vajhøj
4 Aug 24  i+* Re: Simple Pascal question33Dan Cross
4 Aug 24  ii`* Re: Simple Pascal question32Arne Vajhøj
4 Aug 24  ii +* Re: Simple Pascal question4Lawrence D'Oliveiro
5 Aug 24  ii i+* Re: Simple Pascal question2Arne Vajhøj
5 Aug 24  ii ii`- Re: Simple Pascal question1Lawrence D'Oliveiro
5 Aug 24  ii i`- Re: Simple Pascal question1John Reagan
5 Aug 24  ii `* Re: Simple Pascal question27Dan Cross
5 Aug 24  ii  +* Re: Simple Pascal question24Arne Vajhøj
5 Aug 24  ii  i+* Re: Simple Pascal question3Dan Cross
7 Aug 24  ii  ii`* Re: Simple Pascal question2Arne Vajhøj
8 Aug 24  ii  ii `- Re: Simple Pascal question1Dan Cross
5 Aug 24  ii  i+- Re: Simple Pascal question1Lawrence D'Oliveiro
5 Aug 24  ii  i+* Re: Simple Pascal question5Michael S
5 Aug 24  ii  ii+* Re: Simple Pascal question2Lawrence D'Oliveiro
7 Aug 24  ii  iii`- Re: Simple Pascal question1Arne Vajhøj
7 Aug 24  ii  ii`* Re: Simple Pascal question2Arne Vajhøj
7 Aug 24  ii  ii `- Re: Simple Pascal question1Arne Vajhøj
7 Aug 24  ii  i`* Re: Simple Pascal question14Arne Vajhøj
7 Aug 24  ii  i `* Re: Simple Pascal question13Lawrence D'Oliveiro
8 Aug 24  ii  i  +* Re: Simple Pascal question10Arne Vajhøj
8 Aug 24  ii  i  i`* Re: Simple Pascal question9Simon Clubley
8 Aug 24  ii  i  i `* Re: Simple Pascal question8Arne Vajhøj
8 Aug 24  ii  i  i  +- Re: Simple Pascal question1Arne Vajhøj
9 Aug 24  ii  i  i  `* Re: Simple Pascal question6Simon Clubley
9 Aug 24  ii  i  i   `* Re: Simple Pascal question5Arne Vajhøj
9 Aug 24  ii  i  i    `* Re: Simple Pascal question4Dennis Boone
9 Aug 24  ii  i  i     `* Re: Simple Pascal question3Arne Vajhøj
9 Aug 24  ii  i  i      `* Re: Simple Pascal question2Dennis Boone
10 Aug 24  ii  i  i       `- Re: Simple Pascal question1Lawrence D'Oliveiro
8 Aug 24  ii  i  `* Re: Simple Pascal question2Arne Vajhøj
8 Aug 24  ii  i   `- Re: Simple Pascal question1Lawrence D'Oliveiro
5 Aug 24  ii  `* Re: Simple Pascal question2Arne Vajhøj
5 Aug 24  ii   `- Re: Simple Pascal question1Dan Cross
4 Aug 24  i`* Re: Simple Pascal question3John Reagan
5 Aug 24  i `* Re: Simple Pascal question2Arne Vajhøj
7 Aug 24  i  `- Re: Simple Pascal question1Arne Vajhøj
3 Aug 24  `- Re: Simple Pascal question1Arne Vajhøj

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal