Modifies seq<object> #5623
-
Hi, I'm facing an error when attempting to modify a sequence (
The error message is,
While I understand the error, I'm unsure how to correct it. Thank you in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I assume that you want to learn about Sequences cannot be modified, but you can modify an object containing a sequence, e.g. class Seq { var q: seq<object> }
method Push(item: object, s: Seq)
modifies s
{
s.q := s.q+[item];
} or class Seq {
method Push(item: object)
modifies this
{
q := q+[item];
}
var q: seq<object>
} I'm not saying that this is good code. I'm just suggesting "minimal" modifications to make it work. Sequences are values like integers - you cannot modify "5" either. But you can change an object with an integer field by assigning a new integer to that field. You are not changing the integer value. You are changing the object. |
Beta Was this translation helpful? Give feedback.
I assume that you want to learn about
method
smodifying
something, so I'll not suggest that you use afunction
instead.Sequences cannot be modified, but you can modify an object containing a sequence, e.g.
or
I'm not saying that this is good code. I'm just suggesting "minimal" modifications to make it work.
Sequences are values like integers - you cannot modify "5" either. But you can change an object with an integer field by assigning a new integer to that field. You are not …