Re: VMS Pascal article

Liste des GroupesRevenir à co vms 
Sujet : Re: VMS Pascal article
De : cross (at) *nospam* spitfire.i.gajendra.net (Dan Cross)
Groupes : comp.os.vms
Date : 03. Jan 2025, 19:17:25
Autres entêtes
Organisation : PANIX Public Access Internet and UNIX, NYC
Message-ID : <vl99jl$rf6$1@reader2.panix.com>
References : 1 2 3
User-Agent : trn 4.0-test77 (Sep 1, 2010)
In article <67781447$0$711$14726298@news.sunsite.dk>,
Arne Vajhøj  <arne@vajhoej.dk> wrote:
On 1/3/2025 10:11 AM, Dan Cross wrote:
In article <vl3pi8$2r2sr$1@dont-email.me>,
Arne Vajhøj  <arne@vajhoej.dk> wrote:
VMS Pascal for C/Java/C# programmers:
      https://www.vajhoej.dk/arne/articles/vmspascal.html
>
It is a "pre-release" - I am not sure I got it right.
>
So I would love some feedback.
>
C supports 'long double' which _may_ be the same as
`quadruple`, depending on the implementation, though
that's usually 80-bit floats.
>
Very good point. It is 128 bit on VMS unless using /L_DOUBLE=64.
>
Added.
>
I would not say that 'chr' and 'ord' are like casts in C.
Pascal is strongly, statically typed; C is weakly typed with
implicit conversions.  Conversion between characters and integer
types in Pascal is an explicit operation, but `int c = 'a' + 1;`
is perfectly legal in C.
>
It was the best explanation I could come up with.

Why not simply say that Pascal is strongly typed, and C is not?
Conversion from a Pascal character to an integer type requires
using an explicit conversion operation; in C you don't, though
one may cast.

You give two C equivalents of, `round`: `lround` and
`ceil(v + 0.5)`.  Surely the latter should be `trunc(v + 0.5)`:
>
Ooops. All ceil should be floor.
>
Fixed.
>
But, consider negative numbers,
>
Very good point.
>
I have added notes.
>
                                  and note that one would still
have to do a conversion to an integer type.
>
Yes.
>
Fixed.
>
Your C equivalent of `substr` is not correct; exercise left to
the reader (consider what happens when `ix` is beyond the end of
the string).  For that matter, this is true of the VSI Pascal
example as well: you should specify the preconditions that must
be true.
>
Invalid index or length causes an exception in VMS Pascal.
>
But I don't want to get into that level of detail.

*Shrug* it's your document, but in C that'll just be UB.

`readln` and `fgets` are not similar in that `readln` strips the
line ending sequence, and `fgets` does not.
>
Close enough for the purpose of this article.

Perhaps.  I may be worth an asterisk, as often C programmers
will want to write:

    while ((s = fgets(s, len, fp)) != NULL) {
        char *nl = strchr(s, '\n');
        if (nl != NULL)
            *nl = '\0';
    }

Which is a bit more cumbersome than the Pascal equivalent.  When
carriage returns get mixed in, it gets even nastier, so much so
that one may just write a helper function to deal with it.

`f = fopen,fnm "r");` is an obvious typo.
`while not eof(f)) do` is an obvious typo.
>
Fixed.

Fixed, but the comparison to C is slightly wrong:

`while not(eof(f)) do` is not exactly the same as
`while(!feof(f))`.  In particular, while in VSI Pascal `EOF(f)`
will be true on the first iteration of the loop if `f` is empty,
the same is not true for `feof` from stdio: in order for `feof`
to be true, stdio must observe the end-of-file condition of `f`
via some input operation.  This leads to awkward code sequences
like this:

    ch = fgetc(fp);
    while (!feof(fp)) {
        /*
         * Do something with `ch`
         * ...
         */
        ch = fgetc(fp);
    }
       
You may want to mention that Pascal, the semicolon is a
statement separator, not a terminator, and hence why the last
"END" in the protocol is followed by "." and not ";".
>
The article is more what to do than why to do that.

It's actually a rather important syntactical detail of the
language, and the reason one can often omit semi-colons in
surprising ways.  It's the reason one can write, e.g.:

    if foo <> 0 then x := 1 else y := 2;

But hey, it's your document.

The structure you present at the end as "equivalent" of a
varying character array is not correct.  `integer16` is a signed
type, with a maximum value of 32,767.  The length field for a
`varying [n] of char` is an integer subrange type with word
representation.  That is, `length` is unsigned 0..max, where max
is <= 65,535.
>
Ooops.
>
You are right.
>
I was sure that the limit was 32K but it is 64K.
>
Fixed.
>
And also fixed in the description of VARYING further up.

You should seriously mention the STRING type, though.

I would also seriously recommend revising the section on
pointers.

Also, it's a bit of a bummer that you didn't mention nested
functions/procedures, which are among the cooler aspects of the
language:

$ type foo.pas
(* foo *)
program foo(output);
procedure hello;
    procedure world(var who: String);
        function punct: char;
        begin
            punct := '!'
        end;
    begin
        who := 'World' + punct
    end;
var
    who: String (10);
begin
    world(who);
    writeln('Hello, ', who)
end;
begin
    hello
end.
$ pascal foo.pas
$ link foo
$ run foo
Hello, World!
$

- Dan C.


Date Sujet#  Auteur
1 Jan 25 * VMS Pascal article72Arne Vajhøj
1 Jan 25 +* Re: VMS Pascal article3Chris Townley
1 Jan 25 i+- Re: VMS Pascal article1Arne Vajhøj
1 Jan 25 i`- Re: VMS Pascal article1Dennis Boone
2 Jan 25 +* Re: VMS Pascal article18Marc Van Dyck
2 Jan 25 i`* Re: VMS Pascal article17Arne Vajhøj
3 Jan 25 i +* Re: VMS Pascal article5Lawrence D'Oliveiro
3 Jan 25 i i`* Re: VMS Pascal article4Arne Vajhøj
3 Jan 25 i i +* Re: VMS Pascal article2Lawrence D'Oliveiro
3 Jan 25 i i i`- Re: VMS Pascal article1Robert A. Brooks
3 Jan 25 i i `- Re: VMS Pascal article1Simon Clubley
3 Jan 25 i `* Re: VMS Pascal article11Arne Vajhøj
3 Jan 25 i  `* Re: VMS Pascal article10Robert A. Brooks
3 Jan 25 i   `* Re: VMS Pascal article9Arne Vajhøj
3 Jan 25 i    `* Re: VMS Pascal article8Robert A. Brooks
3 Jan 25 i     `* Re: VMS Pascal article7Arne Vajhøj
3 Jan 25 i      `* Re: VMS Pascal article6Robert A. Brooks
4 Jan 25 i       `* Re: SDL, SDLC, PL/I (was Re: VMS Pascal article)5Stephen Hoffman
4 Jan 25 i        +* Re: SDL, SDLC, PL/I (was Re: VMS Pascal article)3Arne Vajhøj
6 Jan 25 i        i`* Re: SDL, SDLC, PL/I (was Re: VMS Pascal article)2Simon Clubley
6 Jan 25 i        i `- Re: SDL, SDLC, PL/I (was Re: VMS Pascal article)1Robert A. Brooks
4 Jan 25 i        `- Re: SDL, SDLC, PL/I (was Re: VMS Pascal article)1Lawrence D'Oliveiro
3 Jan 25 +- Re: VMS Pascal article1David Meyer
3 Jan 25 +* Re: VMS Pascal article24Dan Cross
3 Jan 25 i`* Re: VMS Pascal article23Arne Vajhøj
3 Jan 25 i `* Re: VMS Pascal article22Dan Cross
3 Jan 25 i  `* Re: VMS Pascal article21Arne Vajhøj
3 Jan 25 i   `* Re: VMS Pascal article20Dan Cross
3 Jan 25 i    `* Re: VMS Pascal article19Arne Vajhøj
3 Jan 25 i     +* Re: VMS Pascal article4Dan Cross
3 Jan 25 i     i+* Re: VMS Pascal article2Dan Cross
4 Jan 25 i     ii`- Re: VMS Pascal article1Arne Vajhøj
4 Jan 25 i     i`- Re: VMS Pascal article1Arne Vajhøj
3 Jan 25 i     +* Re: VMS Pascal article2Lawrence D'Oliveiro
4 Jan 25 i     i`- Re: VMS Pascal article1Arne Vajhøj
5 Jan 25 i     `* Coding examples (Re: VMS Pascal article)12David Meyer
5 Jan 25 i      +* Re: Coding examples (Re: VMS Pascal article)2Arne Vajhøj
5 Jan 25 i      i`- Re: Coding examples (Re: VMS Pascal article)1Arne Vajhøj
5 Jan 25 i      `* Re: Coding examples (Re: VMS Pascal article)9Stephen Hoffman
6 Jan 25 i       `* Re: Coding examples (Re: VMS Pascal article)8Marc Van Dyck
6 Jan 25 i        +- Re: Coding examples (Re: VMS Pascal article)1Craig A. Berry
6 Jan 25 i        `* Re: Coding examples (Re: VMS Pascal article)6Arne Vajhøj
6 Jan 25 i         +- Re: Coding examples (Re: VMS Pascal article)1Arne Vajhøj
7 Jan 25 i         +- Re: Coding examples (Re: VMS Pascal article)1mjos_examine
8 Jan 25 i         `* Re: Coding examples (Re: VMS Pascal article)3Craig A. Berry
8 Jan 25 i          `* Re: Coding examples (Re: VMS Pascal article)2Arne Vajhøj
8 Jan 25 i           `- Re: Coding examples (Re: VMS Pascal article)1Lawrence D'Oliveiro
4 Jan 25 +- Re: VMS Pascal article1Martin Vorländer
6 Jan 25 +* Re: VMS Pascal article23John Reagan
7 Jan 25 i`* Re: VMS Pascal article22John Reagan
7 Jan 25 i +* Re: VMS Pascal article20Dan Cross
7 Jan 25 i i`* Re: VMS Pascal article19John Reagan
8 Jan 25 i i `* Re: VMS Pascal article18Dan Cross
8 Jan 25 i i  `* Re: VMS Pascal article17Arne Vajhøj
8 Jan 25 i i   +* Re: VMS Pascal article5Dan Cross
9 Jan 25 i i   i+- Re: VMS Pascal article1Arne Vajhøj
9 Jan 25 i i   i+- Re: VMS Pascal article1Simon Clubley
9 Jan 25 i i   i`* Re: VMS Pascal article2jayjwa
10 Jan 25 i i   i `- Re: VMS Pascal article1Craig A. Berry
9 Jan 25 i i   `* Re: VMS Pascal article11Dave Froble
9 Jan 25 i i    +* Re: VMS Pascal article5Arne Vajhøj
9 Jan 25 i i    i`* Re: VMS Pascal article4Dan Cross
9 Jan 25 i i    i `* Re: VMS Pascal article3Simon Clubley
10 Jan 25 i i    i  `* Re: VMS Pascal article2Simon Clubley
10 Jan 25 i i    i   `- Re: VMS Pascal article1Arne Vajhøj
9 Jan 25 i i    `* Re: VMS Pascal article5Arne Vajhøj
9 Jan 25 i i     +* Re: VMS Pascal article2Robert A. Brooks
9 Jan 25 i i     i`- Re: VMS Pascal article1Arne Vajhøj
9 Jan 25 i i     `* Re: VMS Pascal article2Simon Clubley
9 Jan 25 i i      `- Re: VMS Pascal article1Arne Vajhøj
8 Jan 25 i `- Re: VMS Pascal article1Arne Vajhøj
8 Jan 25 `- Re: VMS Pascal article1Arne Vajhøj

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal