Shop OBEX P1 Docs P2 Docs Learn Events
Looking for a New Solution to Existing SPIN to SPIN2 code — Parallax Forums

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

  • Cluso99Cluso99 Posts: 18,069
    This should work

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

  • JonnyMacJonnyMac Posts: 9,104
    edited 2020-10-12 03:39
    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.