swap   xtlang


Defined in:  https://github.com/digego/extempore/tree/v0.8.9/libs/core/adt.xtm

Implementation

(bind-func swap:[List{!a}*,List{!a}*,i64,i64]*
  ;; swap ith and jth list elements inplace
  (lambda (lst i j)
    (let ((ith_val (nth lst i)))
      (set_car (nth_tail lst i) (nth lst j))
      (set_car (nth_tail lst j) ith_val))
    lst))


Back to Index

Similar Entries