Looking for a New Solution to Existing SPIN to SPIN2 code

The following method worked fine in SPIN:

PUB limitRange(value, lowest, highest)
value #>= lowest
value <#= highest
RETURN value

SPIN2 doesn't like the 'RETURN value'.

PUB limitRange(value, lowest, highest) : value
value #>= lowest
value <#= highest

The above errors to: Expected a unique result name

Comments

  • This should work

    PUB limitRange(value, lowest, highest):result
    result := value
    result #>= lowest
    result <#= highest

  • JonnyMacJonnyMac Posts: 6,997
    edited 2020-10-12 - 03:39:12
    I tested this variant -- it works as you wish:
    pub limit_range(value, lo, hi) : constrained
    
      return lo #> value <# hi
    

    This code is giving you a problem because you are using "value" as a parameter name and the name of the return variable.
    PUB limitRange(value, lowest, highest) : value
      value #>= lowest
      value <#= highest
    
    The above errors to: Expected a unique result name
Sign In or Register to comment.