Skip to content

Modifies seq<object> #5623

Answered by racko
dreamqin68 asked this question in Q&A
Jul 12, 2024 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

I assume that you want to learn about methods modifying something, so I'll not suggest that you use a function instead.

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 …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dreamqin68
Comment options

Answer selected by dreamqin68
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants