Skip to content

Latest commit

 

History

History
66 lines (48 loc) · 1.49 KB

0066-str.org

File metadata and controls

66 lines (48 loc) · 1.49 KB

str

This is a single purpose utility library. Before switching to the str, I used cl-strings, but str library is more consistent.

I like that unlike standard functions, str is able to work with chars and strings as delimiter:

POFTHEDAY> (str:split #\Space
                      "Foo bar bazz")
("Foo" "bar" "bazz")

POFTHEDAY> (str:split " "
                      "Foo bar bazz")
("Foo" "bar" "bazz")

;; Also it is able to skip empty strings:
POFTHEDAY> (str:split " "
                      "Foo   bar   bazz")
("Foo" "" "" "bar" "" "" "bazz")

POFTHEDAY> (str:split-omit-nulls " "
                      "Foo   bar   bazz")
("Foo" "bar" "bazz")

Parameter ordering can seem a little strange at first glance, but they’ve made this way to make it easier to curry functions.

For example, if we have a multiline text and want to put ellipsis at the end of string longer than X, we might do:

POFTHEDAY> (defvar *text* "
This line is much longer than we need.
This one is also too long.

I can't belive!
""")

POFTHEDAY> (str:unlines
            (mapcar (alexandria:curry #'str:shorten 20)
                    (str:lines *text*)))
"
This line is much...
This one is also ...

I can't belive!"

BTW str has very cool documentation. I’d like to have such docs for other CL libraries.