help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: problem with mapconcat


From: Kevin Rodgers
Subject: Re: problem with mapconcat
Date: Wed, 03 Mar 2010 23:56:47 -0700
User-agent: Thunderbird 2.0.0.23 (Macintosh/20090812)

Christian Wittern wrote:
I am trying to build a regex with lisp, which inserts a certain string into another string between each character, for example "abc" should turn into "a/b/c".
With mapconcat, I think this should work:

(mapconcat 'identity (string-to-list "abc") "/")

since the description for mapconcat says

(mapconcat FUNCTION SEQUENCE SEPARATOR)

However, when I try to evaluate this in Emacs 23.1, here it throws the following error:

Debugger entered--Lisp error: (wrong-type-argument sequencep 97)
  mapconcat(identity (97 98 99) "/")
  eval((mapconcat (quote identity) (string-to-list "abc") "/"))

I wonder what I am doing wrong or if there is another way to achieve
 what I am trying to do.

The reason your first attempt failed is that string-to-list returns a list of
characters, and identity obviously returns each character -- but mapconcat
requires that FUNCTION return a string.

As Thamer Mahmoud showed, string-to-list is unnecessary:

(mapconcat 'char-to-string "abc" "/")

--
Kevin Rodgers
Denver, Colorado, USA





reply via email to

[Prev in Thread] Current Thread [Next in Thread]