2019-01-15 11:20:10 +11:00
|
|
|
;;; std.fnl --- A small standard library
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
;; Porting a few functions that I'm used to from other Lisps.
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
(var std {})
|
|
|
|
|
|
|
|
;;;
|
|
|
|
;; Functions
|
|
|
|
|
|
|
|
(fn std.zero? [n]
|
|
|
|
(= 0 n))
|
|
|
|
|
2019-01-15 15:14:29 +11:00
|
|
|
(fn std.fn? [f]
|
|
|
|
(= (type f) :function))
|
|
|
|
|
|
|
|
(fn std.s-empty? [s]
|
|
|
|
(or (= nil s)
|
|
|
|
(= "" s)))
|
|
|
|
|
2019-01-15 15:57:44 +11:00
|
|
|
(fn std.s-split [s sep]
|
|
|
|
(var t {})
|
|
|
|
(let [sep (or sep "%s")
|
|
|
|
re (.. "([^" sep "]+)")]
|
|
|
|
(each [str (string.gmatch s re)]
|
|
|
|
(table.insert t str))
|
|
|
|
t))
|
|
|
|
|
2019-01-15 11:20:10 +11:00
|
|
|
std
|
|
|
|
;;; std.fnl ends here
|