pop - pop value off a variable


<pop $&var [$index]>

The pop function "pops" (removes) a value from $&var, at the index given by $index (default 0). The target variable must be specified with pass-by-reference syntax - i.e. $&var not $var - because it will be modified. Passing it by value would not let it be modified, which might otherwise be a silent bug - hence an error is generated if it is passed by value.

The effective $index value may be zero through one less than the number of pre-existing values of $var. Explicit negative $index values are interpreted as offsets from the end of $var, e.g. -1 is the last value. Out of range or non-integral $index values are a run-time error. An empty-string or zero-values $index is taken as the default, which is 0.

The pop function returns the popped-off value in $ret.


<a name=main>
  <$var = "a" "b" "c">
  <pop $&var 1>
  After: <loop $var> $var </loop>

  ret is $ret

The output of the above example would be:

After: a c
ret is b

The pop function is only valid in syntaxversion 8.


Copyright © Thunderstone Software     Last updated: Oct 24 2023
Copyright © 2024 Thunderstone Software LLC. All rights reserved.