stdlib changes
This commit is contained in:
parent
7f01dfe2f0
commit
288b75c1ad
|
|
@ -1,19 +1,11 @@
|
||||||
; not a bool
|
; not a bool
|
||||||
(defun not (x) (if x 0 1))
|
(defun not (x) (if x 0 1))
|
||||||
|
|
||||||
; negate a number
|
|
||||||
(defun neg (n) (- 0 n))
|
|
||||||
|
|
||||||
; is a number positive?
|
|
||||||
(defun is-pos? (n) (> n 0))
|
(defun is-pos? (n) (> n 0))
|
||||||
|
|
||||||
; is a number negative?
|
|
||||||
(defun is-neg? (n) (< n 0))
|
(defun is-neg? (n) (< n 0))
|
||||||
|
|
||||||
; decrement a number
|
(defun neg (n) (- 0 n))
|
||||||
(defun dec (n) (- n 1))
|
(defun dec (n) (- n 1))
|
||||||
|
|
||||||
; increment a number
|
|
||||||
(defun inc (n) (+ n 1))
|
(defun inc (n) (+ n 1))
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -34,6 +26,20 @@
|
||||||
(defun string-downcase (str)
|
(defun string-downcase (str)
|
||||||
(string-case str "lower"))
|
(string-case str "lower"))
|
||||||
|
|
||||||
|
|
||||||
|
(defun string-join (lst sep)
|
||||||
|
(do
|
||||||
|
(define rslt "")
|
||||||
|
(define i 0)
|
||||||
|
(for e lst
|
||||||
|
(if (= i 0)
|
||||||
|
(define rslt (display e))
|
||||||
|
(define rslt (+ rslt (display sep) (display e))))
|
||||||
|
(define i (inc i)))
|
||||||
|
rslt
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
; pause for interval of seconds
|
; pause for interval of seconds
|
||||||
(defun sleep (time)
|
(defun sleep (time)
|
||||||
(system-cmd (+ "sleep " (string time))))
|
(system-cmd (+ "sleep " (string time))))
|
||||||
|
|
@ -46,7 +52,7 @@
|
||||||
(defun third (l) (index l 2))
|
(defun third (l) (index l 2))
|
||||||
(defun fourth (l) (index l 3))
|
(defun fourth (l) (index l 3))
|
||||||
(defun fifth (l) (index l 4))
|
(defun fifth (l) (index l 4))
|
||||||
(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 0
|
||||||
(defun member (lst itm)
|
(defun member (lst itm)
|
||||||
|
|
@ -81,6 +87,8 @@
|
||||||
(defun make-list (size)
|
(defun make-list (size)
|
||||||
(make-list-of size nil))
|
(make-list-of size nil))
|
||||||
|
|
||||||
|
(defun empty-list? (lst) (and (= (type lst) "list") (= (len lst) 0)))
|
||||||
|
|
||||||
(defun uniq (lst)
|
(defun uniq (lst)
|
||||||
(do
|
(do
|
||||||
(define rslt '())
|
(define rslt '())
|
||||||
|
|
@ -106,7 +114,6 @@
|
||||||
(define rslt (push rslt ee))))
|
(define rslt (push rslt ee))))
|
||||||
(define rslt (push rslt e))
|
(define rslt (push rslt e))
|
||||||
))
|
))
|
||||||
|
|
||||||
rslt
|
rslt
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue