Function: eshell-concat

eshell-concat is a byte-compiled function defined in esh-arg.el.gz.

Signature

(eshell-concat QUOTED &rest REST)

Documentation

Concatenate all the arguments in REST and return the result.

If QUOTED is nil, the resulting value(s) may be converted to numbers (see eshell-concat-1).

If each argument in REST is a non-list value, the result will be a single value, as if (mapconcat #'eshell-stringify REST) had been called, possibly converted to a number.

If there is at least one (non-nil) list argument, the result will be a list, with "adjacent" elements of consecutive arguments concatenated as strings (again, possibly converted to numbers). For example, concatenating "a", ("b"), and ("c" "d") would produce ("abc" "d").

Source Code

;; Defined in /usr/src/emacs/lisp/eshell/esh-arg.el.gz
(defun eshell-concat (quoted &rest rest)
  "Concatenate all the arguments in REST and return the result.
If QUOTED is nil, the resulting value(s) may be converted to
numbers (see `eshell-concat-1').

If each argument in REST is a non-list value, the result will be
a single value, as if (mapconcat #\\='eshell-stringify REST) had been
called, possibly converted to a number.

If there is at least one (non-nil) list argument, the result will
be a list, with \"adjacent\" elements of consecutive arguments
concatenated as strings (again, possibly converted to numbers).
For example, concatenating \"a\", (\"b\"), and (\"c\" \"d\")
would produce (\"abc\" \"d\")."
  (let (result)
    (dolist (i rest result)
      (when i
        (cond
         ((null result)
          (setq result i))
         ((listp result)
          (let (curr-head curr-tail)
            (if (listp i)
                (setq curr-head (car i)
                      curr-tail (cdr i))
              (setq curr-head i
                    curr-tail nil))
            (setq result
                  (append
                   (butlast result 1)
                   (list (eshell-concat-1 quoted (car (last result))
                                          curr-head))
                   curr-tail))))
         ((listp i)
          (setq result
                (cons (eshell-concat-1 quoted result (car i))
                      (cdr i))))
         (t
          (setq result (eshell-concat-1 quoted result i))))))))