Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions PRIMITIVES.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ Note that functions have their names mangled a little bit ("-" is converted to "
* The list is updated in-place.
* `split`
* Split a string by the given character, and return a list of "(before after)". Return nil if the character isn't found.
* `split-all`
* Return a list of all parts of string, split by the character.
* e.g. `(split-all (getenv "PATH") #\:)` to find all directories on the PATH.
* `strcat`
* Join two strings together and return them.
* `strcmp`
Expand Down
18 changes: 18 additions & 0 deletions stdlib.slisp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,24 @@ Incrementing by the given step each time."
"Reverse the contents of the specified list."
(reverse-inner xs nil))

(defun split-all (str char)
"Return a list of splitting the string by the given character.

Empty parts are ignored."
(if (or (nil? str) (= str ""))
nil
(filter (split-all-helper str char) (lambda (x) (> (length x) 0)))))

(defun split-all-helper (str char)
"Recursive helper for splitting a list by character."
(let ((parts (split str char)))
(if (nil? parts)
(list str)
(cons (nth parts 0)
(split-all-helper (nth parts 1) char)))))




;;; system functions

Expand Down
Loading