~xguerin/minima.l

0e35d9e33f1efd10996685b6cd70fe88712703a8 — Xavier R. Guerin 2 months ago fb4d12b
Add JOIN and TRIM functions
3 files changed, 34 insertions(+), 0 deletions(-)

M docs/manual/Reference.md
A share/mnml/join.l
A share/mnml/trim.l
M docs/manual/Reference.md => docs/manual/Reference.md +2 -0
@@ 57,8 57,10 @@
| Name      | Syntax                      | Module | Description |
|:----------|:----------------------------|:------:|:------------|
| `ntoa`      | `(ntoa 'num)`                 |        | Convert `num` into a string |
| `join`      | `(join 'lst 'chr)`            |        | Join `lst` of strings into a `chr`-separted string |
| `split`     | `(split 'str 'chr)`           |        | Split `str` of `chr`-separted tokens |
| `str`       | `(str 'sym)`                  | `std`    | Make a string out of `sym` |
| `trim`      | `(trim 'str)`                 |        | Trim `str` of leading and trailing white spaces |

#### Symbol definition


A share/mnml/join.l => share/mnml/join.l +9 -0
@@ 0,0 1,9 @@
(load
	"append.l"
	"iterators.l"
	"rev.l"
	'(std let \ car cdr list))

(def join (lst chr)
	(let ((rlst . (rev lst)))
		(foldl (\ (acc e) (append e (list chr) acc)) (car rlst) (cdr rlst))))

A share/mnml/trim.l => share/mnml/trim.l +23 -0
@@ 0,0 1,23 @@
(load
	"iterators.l"
	"rev.l"
	'(logic = or)
	'(std \ |> car cdr cons if))

(def whitespace? (chr)
	"Return T if CHR is a white space."
	(|> (= chr ^ ) (or (= chr ^\t)) (or (= chr ^\n)) (or (= chr ^\r))))

(def triml (strn)
	"Trim STRN of leading white spaces."
	(if (whitespace? (car strn))
		(triml (cdr strn))
		strn))

(def trimr (strn)
	"Trim STRN of trailing white spaces."
	(rev (triml (rev strn))))

(def trim (strn)
	"Trim STRN of leading and trailing white spaces."
	(trimr (triml strn)))