vladfolts / oberonjs

Oberon 07 compiler (written in JavaScript and translates to JavaScript)
MIT License
132 stars 22 forks source link

Function call treats as statement. #6

Closed valexey closed 11 years ago

valexey commented 11 years ago

According #10 of Oberon 07/11 report:

There are two kinds of procedures, namely proper procedures and function procedures. The latter are activated by a function designator as a constituent of an expression, and yield a result that is an operand in the expression.

So, procedure-function call can be only part of expression. But at current compiler realization such call can be treats as statement:

MODULE test;

PROCEDURE Foo() : INTEGER; RETURN 42 END Foo;

BEGIN
    Foo (* compiler must report error here *)
END test.
vladfolts commented 11 years ago

Oh my... I would not interpret the report saying in this way but it seems like existing implementations (BlackBox) prohibit function calls as a statement. Is there at least one good practical point for this behavior?

valexey commented 11 years ago

No. In BlackBox:

MODULE Test;    
    PROCEDURE Test() : INTEGER;
    BEGIN
        RETURN 42;
    END Test;
BEGIN
    Test(); (* error: procedure call of a function *)
END Test.
vladfolts commented 11 years ago

I said the same thing - in BB it is prohibited (compiler error) :)

valexey commented 11 years ago

I think that according Oberon-07/11 report our compiler must prohibit function call as statement.

vladfolts commented 11 years ago

Still I wonder why do not write it clearly in report, e.g. "procedures returning result cannot be used as a statement". Instead of all of these "proper procedures" etc...

vladfolts commented 11 years ago

Fixed.