Program name declaration 
Author Message
 Program name declaration

I wouldn't say this is an important question but it's one I've thought
of for a while.

When I started using TP, I understood the "Program" declaration at the
start to be like this:
   Program <name>(<files used>)

most commonly:
   Program <name>(input, output)

The TP Help says "Program ... ..." is itself just decorative, so is the
<files used> part needed at all? Or is it just for clarification, as
comments ( {..} ) are?

--

Faculty Of Science, University Of Liverpool
http://www.*-*-*.com/

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Wed, 18 Jun 1902 08:00:00 GMT  
 Program name declaration


Quote:
> I wouldn't say this is an important question but it's one I've thought
> of for a while.

> When I started using TP, I understood the "Program" declaration at the
> start to be like this:
>    Program <name>(<files used>)

> most commonly:
>    Program <name>(input, output)

> The TP Help says "Program ... ..." is itself just decorative, so is the
> <files used> part needed at all? Or is it just for clarification, as
> comments ( {..} ) are?

Not needed at all at all in TP/BP. It's completely ignored. You can start
your .pas main program file by going straight to a type or var statement.
But it looks nicer with a Program line. And maybe other Pascals require it.

FP



Wed, 18 Jun 1902 08:00:00 GMT  
 Program name declaration
     The Program statement is part of the Pascal Standard (to which Borland
does not adhere).  If you think about Pascal as a block-oriented language,
each block starts with a declaration (e.g. PROCEDURE, FUNCTION), followed
by declarations (CONST, TYPE, VAR, perhaps other blocks), and finally a
(compound) statement inside BEGIN ... END pairs.  You can think of the
PROGRAM statement as extending this block analogy to the level of the
entire program.  Now the entire program has a unified structure:  Block
heading, block declarations, and block statement(s), where block
declarations can include other blocks.

     PROCEDURE and FUNCTION statements have formal parameters which
describe the variables, known "outside" the block, that become "known"
within the block.  The PROGRAM parameters function in a similar way, since
they identify the (external) file variables that will exist "outside" the
context of the executing program.

     It is my understanding that, in the Borland dialect of Pascal, the
PROGRAM statement is ignored.  You might consider including it, both for
the symmetry it gives to your code, and the ability to identify "up front"
the external (file) variables that the program uses.  Finally, if you ever
need to write a program (such as a Pretty Printer) that acts on Pascal
source code, the unified (recursive) block definition for the entire
program will simplify your efforts greatly!

Bob Schor
Pascal Enthusiast

Quote:

> I wouldn't say this is an important question but it's one I've thought
> of for a while.

> When I started using TP, I understood the "Program" declaration at the
> start to be like this:
>    Program <name>(<files used>)

> most commonly:
>    Program <name>(input, output)

> The TP Help says "Program ... ..." is itself just decorative, so is the
> <files used> part needed at all? Or is it just for clarification, as
> comments ( {..} ) are?

> --

> Faculty Of Science, University Of Liverpool
> http://www.liv.ac.uk

> Sent via Deja.com http://www.deja.com/
> Before you buy.



Wed, 18 Jun 1902 08:00:00 GMT  
 Program name declaration

Quote:

>     It is my understanding that, in the Borland dialect of Pascal, the
>PROGRAM statement is ignored.  You might consider including it, both for
>the symmetry it gives to your code, and the ability to identify "up front"
>the external (file) variables that the program uses.

had you programmed anything on Turbo Pascal yo woudl know how funny that
sounds. Why would anyone in the first place be interested in names of
the file variables that some routines uses. What if those are used in
some unit.

I typically use just FP as file variable. That is almost always defined
as a local variable in a procedure or sometimes a function. Because the
file variable is internal to the subroutine, I see no reason whatsoever
to list it in the program header. That would go against the
very structural nature of Pascal.

Osmo



Wed, 18 Jun 1902 08:00:00 GMT  
 Program name declaration


Quote:

>     It is my understanding that, in the Borland dialect of Pascal, the
>PROGRAM statement is ignored.  

That is not quite true.

The word program must be followed by an identifier (which is indeed
checked for not being a reserved word); and the identifier cannot be
redeclared in the outer block.  Assertions have just been tested in BP7.

The text in the manual is in this respect incomplete.

The railway diagram and the on-line help imply that the (...) part of
the statement contains parameters, not just file parameters; IMHO there
is some potential for a good idea here somewhere, and a language could
be specified so that the actual command-line parameters had to be
compatible with the indications, or would be read into the variables,
there given.

--

 Web <URL: http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
 Proper 4-line sig. separator is as above, a line exactly "-- " (SonOfRFC1036)
 Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)



Wed, 18 Jun 1902 08:00:00 GMT  
 Program name declaration

Quote:
>      It is my understanding that, in the Borland dialect of Pascal, the
> PROGRAM statement is ignored.  

Do you know if any Pascal dialect allows nested "programs", like M2's
local modules? (which pretty much are like nested programs or nested
units.

Quote:
> You might consider including it, both for
> the symmetry it gives to your code, and the ability to identify "up
> front"  the external (file) variables that the program uses.  

???
I never saw a

program xxx(input,output,stderr);

 :-)

Quote:
> need to write a program (such as a Pretty Printer) that acts on Pascal
> source code, the unified (recursive) block definition for the entire
> program will simplify your efforts greatly!

This is why I replied (and asked the first question) Afaik a mandatory
"program" line is only easier for parsing when the language allows
nested programs/unit statements. And actually, in M2 it IS mandatory :-)

--




Wed, 18 Jun 1902 08:00:00 GMT  
 Program name declaration


Quote:
> Do you know if any Pascal dialect allows nested "programs", like M2's
> local modules? (which pretty much are like nested programs or nested
> units.

Standard Pascal (as defined by ISO 7185:1990) does not allow nested
programs.  Only Procedures and Functions can be "declared" within a program.

Quote:
> I never saw a

> program xxx(input,output,stderr);

>  :-)

All of my programs that do NOT use external files have, as their first line,

PROGRAM whatever (input, output);

[where I substitute something else, obviously, for "whatever"].

Quote:
> > need to write a program (such as a Pretty Printer) that acts on Pascal
> > source code, the unified (recursive) block definition for the entire
> > program will simplify your efforts greatly!

> This is why I replied (and asked the first question) Afaik a mandatory
> "program" line is only easier for parsing when the language allows
> nested programs/unit statements. And actually, in M2 it IS mandatory :-)

It is also mandatory in Standard Pascal.

Bob Schor
Pascal Enthusiast



Wed, 18 Jun 1902 08:00:00 GMT  
 Program name declaration

Quote:

>>  :-)

>All of my programs that do NOT use external files have, as their first line,

>PROGRAM whatever (input, output);

My point exactly. Most OSes (dos,windows and *nix) define at least three
standard files. (input,output and error)

Quote:
>> > need to write a program (such as a Pretty Printer) that acts on Pascal
>> > source code, the unified (recursive) block definition for the entire
>> > program will simplify your efforts greatly!

>> This is why I replied (and asked the first question) Afaik a mandatory
>> "program" line is only easier for parsing when the language allows
>> nested programs/unit statements. And actually, in M2 it IS mandatory :-)

>It is also mandatory in Standard Pascal.

Ok, but in M2 I can see a clear reason. (and because in M2 both programs and
units start with module <x>)
But luckily this is the TP NG, and as such not standard pascal :-)


Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Name and directory of the current program.

2. Change program name

3. Give names of Programs/Games written in Pascal!

4. Program name TSR

5. Pointer declarations

6. Variant fields in object declaration in TP7 or DELPHI

7. declaration error

8. ODBC32 API Declaration Unit for Delphi 2.0

9. {10:3 declaration}????

10. write / writeln declaration

11. Help: Unfamiliar type declaration

12. Help: Unfamiliar type declaration

 

 
Powered by phpBB® Forum Software