take   xtlang


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

Implementation

(bind-func take:[List{!a}*,List{!a}*,i64]*
  "returns a copy of the first n elements of lst"
  (lambda (lst n)
    (let ((newlst (list))
          (oldlst lst)
          (count 0))
      (while (and (< count n)
                  (not (null? oldlst)))
        (set! newlst (cons (car oldlst) newlst))
        (set! oldlst (cdr oldlst))
        (set! count  (+ count 1)))
      (reverse newlst))))


Back to Index

Similar Entries

  • take    scheme
  • take-token    scheme
  • take-while    scheme