I could not figure out how to get a list out of this (my/tf :str nil "foo" )
.
This function returns a concatenated string of directories or a list.
Function Must:
- Return a string when one argument is given OR :str t
- Return a list when more than 1 argument is given OR :str nil
(cl-defun my/tf (&rest rest &key (str "_") (ex t) &allow-other-keys )
(let ((new-list (cl-remove-if-not #'stringp rest))
(dir user-emacs-directory ))
(if rest (if (and (not (equal str t)) (< 1 (length new-list) )) ; Return list when more than one arg.
;; Return list
(mapcar (lambda (str-arg)
(if ex (expand-file-name str-arg dir )
(concat (abbreviate-file-name dir) str-arg )
)) new-list)
;; Return string - Concat arguments separated by space.
(mapconcat (lambda (str-arg)
(if ex (expand-file-name str-arg dir )
(concat (abbreviate-file-name dir) str-arg )
)) new-list " "))
(expand-file-name user-emacs-directory))))
;; WORKS
(my/tf "foo" "bar" ) ;("/home/rick/.config/emacs/foo" "/home/rick/.config/emacs/bar")
(my/tf "foo" ) ; ⇒ "/home/rick/.config/emacs/foo"
(my/tf :str t "foo" ) ; ⇒ "/home/rick/.config/emacs/foo"
(my/tf :ex nil "foo" "bar" ) ; ⇒ ("~/.config/emacs/foo" "~/.config/emacs/bar")
(my/tf :ex nil :str t "foo" "bar" ) ; ⇒ "~/.config/emacs/foo ~/.config/emacs/bar"
;; DON’T WORK
;; When I use the (or (= 1 (length new-list) )(< 1 (length new-list)))
;; it messes the other ones up.
; Need a list when :str nil ⇒ ("/home/rick/.config/emacs/foo")
(my/tf :str nil "foo" ) ; ⇒ "/home/rick/.config/emacs/foo"
(not :str)
tests that.)elisp-macros
,defun
, options,let-binding
, etc.). Your question is not about Elisp as a variety of Lisp, i.e., compared with other Lisps. It looks like your question is maybe about lists and using conditionals.