gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fwd: cannot declare function


From: Benjamin Kowarsch
Subject: Re: Fwd: cannot declare function
Date: Mon, 14 Oct 2024 11:12:35 +0900


On Sun, 13 Oct 2024 at 20:44, Alexey Ulasevich wrote:

I investigated "The Programming Language Modula-2" more careful, like I got from "10. Procedure declarations" and "10.1 Formal parameters", when procedure does not return any result we can miss brackets. So next code also Ok (but with brackets it's really more readable):


Don't mix up functions and procedures. In his urge for simplification, sometimes oversimplification, Wirth appears to have wanted to avoid two separate reserved words, FUNCTION and PROCEDURE as was the case in Pascal, so he chose PROCEDURE alone to be used for both functions and procedures.

But functions remain functions, called function procedures in Modula-2 terminology. And procedures remain procedures, called proper procedures in Modula-2 terminology. Function procedures return arguments in their own name, proper procedures do not.

In your first example, procedure Calc is a function procedure, in your second example it is a proper procedure.

When calling a function procedure, use parentheses.

When calling a parameterless proper procedure, no parentheses are required.

And then, perhaps you want to adhere to one of two naming conventions ...

(1) function names start with a lowercase letter, procedure names with an uppercase letter; or
(2) function names start with an uppercase letter, procedure names with a lowercase letter.

The rationale behind convention #1 is to be in line with math usage where functions are always lowercase. The rationale behind convention #2 is that function names represent nouns, and procedure names represent verbs.

Gaius, the error messages in the presented case are really confusing. The compiler should know that it expects a function call with parentheses and then report the missing parentheses accordingly. Instead, it sends the user on a wild goose chase. You may want to improve theĀ error reporting for this.

regards
benjamin

reply via email to

[Prev in Thread] Current Thread [Next in Thread]