insert   xtlang


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

Implementation

(bind-func insert:[List{!a}*,List{!a}*,i64,!a]*
  (lambda (lst idx value)
    (if (= idx 0)
        (cons value lst)
        (let ((pre_cell (nth_tail lst (- idx 1)))
              (new_cell (cons value (cdr pre_cell))))
          (tset! pre_cell 1 new_cell)
          lst))))


Back to Index

Similar Entries