ludic/docs/language/list/list-clear.md

806 B

id name category kind tokens sig tip order ns member
list-clear List.clear list namespace-method List.clear List.clear(s) -> void Remove all elements, keeping capacity. 2 List clear

Empties s by setting its length back to zero. The backing buffer is kept, so refilling the slice afterward reuses the same memory without reallocating. Use it to reset a per-frame list — collisions, visible tiles, particles to draw — at the start of each update instead of building a new slice every frame.

Parameters:

  • s — the slice to empty
program FrameHits {
  state FrameHitsState {
    hits: []int = new []int
  }

  handler BeginFrame(frame_hits_st: FrameHitsState) phase Update {
    List.clear(frame_hits_st.hits)   # start the frame with an empty list
  }
}