take functions added

This commit is contained in:
vaclavt 2022-01-22 23:04:05 +01:00
parent d72b758c59
commit 1bbbee24fe
1 changed files with 6 additions and 2 deletions

View File

@ -60,7 +60,7 @@
(defun tenth (l) (index l 9)) (defun tenth (l) (index l 9))
(defun nth (i l) (index l (- i 1))) (defun nth (i l) (index l (- i 1)))
; return 1 when list contains item otherwise 0 ; return 1 when list contains item otherwise nil
(defun member (lst itm) (defun member (lst itm)
(do (do
; TODO check if is empty list ; TODO check if is empty list
@ -74,7 +74,6 @@
(set! i (+ i 1)) (set! i (+ i 1))
)) ))
; TODO when nil will be implemented itm / nil
(if (!= -1 found_index) (if (!= -1 found_index)
#t #t
nil) nil)
@ -122,6 +121,11 @@
)) ))
rslt rslt
)) ))
(defun take (lst n)
(if (> (len lst) n)
(map (lambda (i) (index lst i)) (range 0 n))
lst))
(defun quick-sort-by (l cmp) (defun quick-sort-by (l cmp)
(if (<= (len l) 1) (if (<= (len l) 1)