vindarel / cl-str

Modern, simple and consistent Common Lisp string manipulation library.
https://vindarel.github.io/cl-str/
MIT License
305 stars 37 forks source link

Add specific character strings variables #111

Open kilianmh opened 9 months ago

kilianmh commented 9 months ago

Since some functions (such as concat) only accept strings. Therefore sometimes it is convenient to have characters as strings. E.g.

(defvar new-line (string #\Newline))

The we could use it in concat like this:

(str:concat "Hello" new-line "world") 

It could be useful, especially for the whitespace characters (e.g. for space) but maybe also others. What do you think?

vindarel commented 8 months ago

Some functions have been worked out to also accept characters:

(str:join #\Newline '( "hello" "test"))

so I think we should allow characters for all, including concat.

kilianmh commented 8 months ago

we should allow characters for all, including concat

good idea. Could concat also accept numbers?

2.

The only annoying thing with characters is the special syntax #\. So what you think if we define e.g. whitespace-characters as variable / constant to make it more "lispy" working with characters. For example:

(defvar new-line #\Newline)
(defconstant tab #\Tab)

3.

Also one idea was introducing functions such as new-lines (or new-line?), that contain multiple times the same characters:

(defun new-lines (lines)
  (let ((result ""))
    (dotimes (var lines)
    (setf result (str:concat result "
")))
    result))
CL-USER> (new-lines 2)
"

"