Kalle
Kalle

Reputation: 384

Use cases in operations in VDM++

Im pretty new to VDM++ and im trying to use cases in a operation to see how it works.

My idea was to give the operation an input and see what it gave me as output. So fx. my input could be: and I would expect output to be Even.

The following operations fails and give me the error "Unexpected token in expression"

public sign: (seq of char) ==> (seq of char)
sign(sign) ==
cases sign:
    <Even> -> "Even",
    <Odd> -> "Odd",
    others -> "Unknown"
end

Upvotes: 0

Views: 185

Answers (1)

Nick Battle
Nick Battle

Reputation: 703

Hopefully the error is actually Unexpected token in statement (not expression?). The cases statement requires the RHS of each case clause to be a statement. So you would have to say -> return "Even". Alternatively, you can say return cases sign: ..., turning it into one large return statement, where the cases expression that followed it would then be correctly formed.

Upvotes: 0

Related Questions