Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Vini, vidi, Linux! -- Unknown source


devel / comp.lang.lisp / .Re: Emacs Lisp's "mapconcat" in Common Lisp?

SubjectAuthor
o .Re: Emacs Lisp's "mapconcat" in Common Lisp?Robert L.

1
.Re: Emacs Lisp's "mapconcat" in Common Lisp?

<suqkc4$10oe$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16900&group=comp.lang.lisp#16900

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!gSXBwBB/iIprw9K3nELhqg.user.46.165.242.75.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (Robert L.)
Newsgroups: comp.lang.lisp
Subject: .Re: Emacs Lisp's "mapconcat" in Common Lisp?
Date: Sat, 19 Feb 2022 11:30:13 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <suqkc4$10oe$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Info: gioia.aioe.org; logging-data="33550"; posting-host="gSXBwBB/iIprw9K3nELhqg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: XanaNews/1.18.1.6
X-Notice: Filtered by postfilter v. 0.9.2
 by: Robert L. - Sat, 19 Feb 2022 11:30 UTC

Pascal Bourguignon wrote:

> Teemu Likonen <tlikonen@iki.fi> writes:
>
> > It's a Common Lisp newbie here; I'm more experienced in Emacs Lisp. I
> > wonder if there is similar function in CL like Emacs Lisp's "mapconcat":
> >
> > (mapconcat 'identity '("one" "two" "three") "-")
> > => "one-two-three"
> >
> > I can do the same in CL with this:
> >
> > (let ((list '("one" "two" "three")))
> > (format nil "~{~a-~}~a" (butlast list) (car (last list))))
> >
> > But I have a feeling that there could be a more elegant way. Is there?
>
> Yes, write: (mapconcat 'identity '("one" "two" "three") "-") ; elegant!
>
>
> Of course, with:
>
>
> (defun mapconcat (fun list sep)
> (when list
> (let ((~sep (with-output-to-string (*standard-output*)
> (map nil (lambda (ch) (princ (if (char= #\~ ch) "~~" ch)))
> sep))))
> (format nil (format nil "~~A~~{~A~~A~~}" ~sep)
> (funcall fun (first list))
> (mapcar fun (rest list))))))
>
>
>
> (mapconcat 'identity '("one" "two" "three") "-")
> --> "one-two-three"
>
> (mapconcat (lambda (x) (concatenate 'string "[" x "]")) '("one" "two" "three") "
> ~")
> --> "[one]~[two]~[three]"

Gauche Scheme:

(define (mapconcat fun lst sep)
(reduce-right
(cut string-append <> sep <>)
""
(map fun lst)))

(mapconcat values '("one" "two" "three") "-")
===>
"one-two-three"

(mapconcat x->string '("one" 2 three) "-")
===>
"one-2-three"


devel / comp.lang.lisp / .Re: Emacs Lisp's "mapconcat" in Common Lisp?

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor