PLC-lang/rusty

Improved Method/Function value return syntax

Ouverte

#1 094 ouverte le 13 févr. 2024

 (8 commentaires) (0 réaction) (0 personne assignée)Rust (71 forks)auto 404
enhancementgood first issue

Métriques du dépôt

Stars
 (351 étoiles)
Métriques de merge PR
 (Métriques PR en attente)

Description

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```

Guide contributeur