rusty icon indicating copy to clipboard operation
rusty copied to clipboard

Improved Method/Function value return syntax

Open TheColonel2688 opened this issue 6 months ago • 8 comments

The IEC 61131-3 Syntax for the returned Value from a Method or Function isn't very readable.

The syntax is *functionName* := *Value to Return*

I was actually trying to find the section of IEC 61131-3 that requires this syntax, but I can't seem to find it. I found code examples in the standard that use it, though. Could someone point me to it? I have a copy of the 3rd edition.

My proposal is an alternate syntax that is in line with almost all other modern languages. The system uses "return" as an alias over the function name. This ideal would be an optional syntax to maintain compatibility. return := *value to return*

FUNCTION mySumFunc : DINT
VAR_INPUT
    Blah_Blah1 : DINT;
    Blah_Blah2 : DINT;
VAR_END
return := Blah_Blah1 + Blah_Blah2;
END FUNCTION

This, I think, is much more readable and will also help with implementing Properties. (I will create another feature request for Properties)

Edit:

The new proposed syntax is the following with no := operator

VAR_INPUT
    Blah_Blah1 : DINT;
    Blah_Blah2 : DINT;
VAR_END
  RETURN Blah_Blah1 + Blah_Blah2; 
END FUNCTION```

TheColonel2688 avatar Feb 13 '24 15:02 TheColonel2688