cl-str icon indicating copy to clipboard operation
cl-str copied to clipboard

Add specific character strings variables

Open kilianmh opened this issue 2 years ago • 2 comments

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?

kilianmh avatar Dec 09 '23 11:12 kilianmh

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.

vindarel avatar Dec 20 '23 10:12 vindarel

we should allow characters for all, including concat

good idea. Could concat also accept numbers?

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)

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)
"

"

kilianmh avatar Dec 23 '23 20:12 kilianmh