Skip to main content

patch_seq_list_set

Function patch_seq_list_set 

Source
#[unsafe(no_mangle)]
pub unsafe extern "C" fn patch_seq_list_set(stack: Stack) -> Stack
Expand description

Set an element in a list by index with COW optimization.

Stack effect: ( Variant Int Value – Variant Bool )

Fast path: if the list (at sp-3) is sole-owned and the index (at sp-2) is a valid tagged int, peeks at both without popping, then pops value and index and mutates the list in place. Slow path: pops all three, clones if shared, pushes new list.

Returns the list with the value at the given index replaced, and true. If index is out of bounds, returns the original list and false.

§Error Handling

  • Empty stack: Sets runtime error, returns unchanged stack
  • Type mismatch: Sets runtime error, returns original list and false
  • Out of bounds: Returns original list and false (no error set, this is expected)

§Safety

Stack must have Value on top, Int below, and Variant (list) below that