mirror of
https://github.com/peklaiho/madlisp.git
synced 2024-11-22 13:24:46 +00:00
add util.mad with some utility functions
This commit is contained in:
parent
215c694bea
commit
b1c1eb5cf1
16
mad/util.mad
Normal file
16
mad/util.mad
Normal file
@ -0,0 +1,16 @@
|
||||
|
||||
;;
|
||||
;; Generic utility functions.
|
||||
;;
|
||||
|
||||
;; Return first item of sequence, or null if it is empty.
|
||||
(defn first-or-null (seq) (if (empty? seq) null (first seq)))
|
||||
|
||||
;; Split string by whitespace, removing empty strings.
|
||||
(defn split-ws (s) (re-split "/[\\s]+/" s))
|
||||
|
||||
;; Split string by whitespace into first and rest.
|
||||
;; Useful for parsing a string for command name and arguments.
|
||||
(defn str-first-rest (s)
|
||||
(let (words (split-ws s))
|
||||
[(first-or-null words) (tail words)]))
|
Loading…
Reference in New Issue
Block a user