all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* problem with mapconcat
@ 2010-03-03 12:49 Christian Wittern
  2010-03-03 13:50 ` Dan Davison
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Christian Wittern @ 2010-03-03 12:49 UTC (permalink / raw)
  To: help-gnu-emacs

Hi there,

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.

Any help appreciated,

Christian





^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: problem with mapconcat
  2010-03-03 12:49 problem with mapconcat Christian Wittern
@ 2010-03-03 13:50 ` Dan Davison
  2010-03-03 13:55   ` Christian Wittern
  2010-03-03 13:57 ` Teemu Likonen
  2010-03-04  6:56 ` Kevin Rodgers
  2 siblings, 1 reply; 11+ messages in thread
From: Dan Davison @ 2010-03-03 13:50 UTC (permalink / raw)
  To: Christian Wittern; +Cc: help-gnu-emacs

Christian Wittern <cwittern@gmail.com> writes:

> Hi there,
>
> 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.

These do it

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

Dan

>
> Any help appreciated,
>
> Christian




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: problem with mapconcat
  2010-03-03 13:50 ` Dan Davison
@ 2010-03-03 13:55   ` Christian Wittern
  0 siblings, 0 replies; 11+ messages in thread
From: Christian Wittern @ 2010-03-03 13:55 UTC (permalink / raw)
  To: Dan Davison; +Cc: help-gnu-emacs

On 2010-03-03 22:50, Dan Davison wrote:
> These do it
> (mapconcat 'char-to-string (string-to-list "abc") "/")
> (mapconcat 'identity (split-string "abc" "" t) "/")
>
> Dan
>    
Ah, indeed!  That is great, thanks!

Christian





^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: problem with mapconcat
  2010-03-03 12:49 problem with mapconcat Christian Wittern
  2010-03-03 13:50 ` Dan Davison
@ 2010-03-03 13:57 ` Teemu Likonen
  2010-03-03 15:23   ` Thamer Mahmoud
  2010-03-04  6:56 ` Kevin Rodgers
  2 siblings, 1 reply; 11+ messages in thread
From: Teemu Likonen @ 2010-03-03 13:57 UTC (permalink / raw)
  To: Christian Wittern; +Cc: help-gnu-emacs

* 2010-03-03 12:49 (UTC), 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".

(mapconcat #'identity (mapcar #'char-to-string "abc") "/")

=> "a/b/c"




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: problem with mapconcat
  2010-03-03 13:57 ` Teemu Likonen
@ 2010-03-03 15:23   ` Thamer Mahmoud
  2010-03-03 15:41     ` Thamer Mahmoud
  0 siblings, 1 reply; 11+ messages in thread
From: Thamer Mahmoud @ 2010-03-03 15:23 UTC (permalink / raw)
  To: help-gnu-emacs

Teemu Likonen <tlikonen@iki.fi> writes:

> * 2010-03-03 12:49 (UTC), 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".
>
> (mapconcat #'identity (mapcar #'char-to-string "abc") "/")
>
> => "a/b/c"

Another alternative:

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

=> "a/b/c"






^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: problem with mapconcat
  2010-03-03 15:23   ` Thamer Mahmoud
@ 2010-03-03 15:41     ` Thamer Mahmoud
  2010-03-04  1:39       ` Christian Wittern
  2010-03-04  7:36       ` Andreas Röhler
  0 siblings, 2 replies; 11+ messages in thread
From: Thamer Mahmoud @ 2010-03-03 15:41 UTC (permalink / raw)
  To: help-gnu-emacs

Thamer Mahmoud <thamer.mahmoud@gmail.com> writes:
> Another alternative:
>
> (mapconcat 'string (string-to-list "abc") "/")
>
> => "a/b/c"

After sending the above, I realized that this would work too:

(mapconcat 'string "abc" "/")






^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: problem with mapconcat
  2010-03-03 15:41     ` Thamer Mahmoud
@ 2010-03-04  1:39       ` Christian Wittern
  2010-03-04  7:36       ` Andreas Röhler
  1 sibling, 0 replies; 11+ messages in thread
From: Christian Wittern @ 2010-03-04  1:39 UTC (permalink / raw)
  To: help-gnu-emacs

Thamer Mahmoud <thamer.mahmoud <at> gmail.com> writes:

> 
> After sending the above, I realized that this would work too:
> 
> (mapconcat 'string "abc" "/")
> 
Great, this seems to be the simplest, thank you!

Christian 








^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: problem with mapconcat
  2010-03-03 12:49 problem with mapconcat Christian Wittern
  2010-03-03 13:50 ` Dan Davison
  2010-03-03 13:57 ` Teemu Likonen
@ 2010-03-04  6:56 ` Kevin Rodgers
  2 siblings, 0 replies; 11+ messages in thread
From: Kevin Rodgers @ 2010-03-04  6:56 UTC (permalink / raw)
  To: help-gnu-emacs

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





^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: problem with mapconcat
  2010-03-03 15:41     ` Thamer Mahmoud
  2010-03-04  1:39       ` Christian Wittern
@ 2010-03-04  7:36       ` Andreas Röhler
  2010-03-04  9:35         ` Stephen Berman
  1 sibling, 1 reply; 11+ messages in thread
From: Andreas Röhler @ 2010-03-04  7:36 UTC (permalink / raw)
  To: help-gnu-emacs

Thamer Mahmoud wrote:
> Thamer Mahmoud <thamer.mahmoud@gmail.com> writes:
>> Another alternative:
>>
>> (mapconcat 'string (string-to-list "abc") "/")
>>
>> => "a/b/c"
> 
> After sending the above, I realized that this would work too:
> 
> (mapconcat 'string "abc" "/")
> 
> 
> 
> 
> 

That seems to work either, whats strange for me:

(mapconcat 'list "abc" "/")"a/b/c"


Andreas




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: problem with mapconcat
  2010-03-04  7:36       ` Andreas Röhler
@ 2010-03-04  9:35         ` Stephen Berman
  2010-03-04 15:07           ` Andreas Röhler
  0 siblings, 1 reply; 11+ messages in thread
From: Stephen Berman @ 2010-03-04  9:35 UTC (permalink / raw)
  To: help-gnu-emacs

On Thu, 04 Mar 2010 08:36:46 +0100 Andreas Röhler <andreas.roehler@easy-emacs.de> wrote:

> Thamer Mahmoud wrote:
>> Thamer Mahmoud <thamer.mahmoud@gmail.com> writes:
>>> Another alternative:
>>>
>>> (mapconcat 'string (string-to-list "abc") "/")
>>>
>>> => "a/b/c"
>> 
>> After sending the above, I realized that this would work too:
>> 
>> (mapconcat 'string "abc" "/")
>> 
>> 
>> 
>> 
>> 
>
> That seems to work either, whats strange for me:
>
> (mapconcat 'list "abc" "/")"a/b/c"

Maybe this helps clarify why that works:

(let (r)
  (dolist (e (string-to-list "abc") r)
    (setq r (concat r (if (null r) "" "/") (list e)))))

Steve Berman





^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: problem with mapconcat
  2010-03-04  9:35         ` Stephen Berman
@ 2010-03-04 15:07           ` Andreas Röhler
  0 siblings, 0 replies; 11+ messages in thread
From: Andreas Röhler @ 2010-03-04 15:07 UTC (permalink / raw)
  To: help-gnu-emacs

Stephen Berman wrote:
> On Thu, 04 Mar 2010 08:36:46 +0100 Andreas Röhler <andreas.roehler@easy-emacs.de> wrote:
> 
>> Thamer Mahmoud wrote:
>>> Thamer Mahmoud <thamer.mahmoud@gmail.com> writes:
>>>> Another alternative:
>>>>
>>>> (mapconcat 'string (string-to-list "abc") "/")
>>>>
>>>> => "a/b/c"
>>> After sending the above, I realized that this would work too:
>>>
>>> (mapconcat 'string "abc" "/")
>>>
>>>
>>>
>>>
>>>
>> That seems to work either, whats strange for me:
>>
>> (mapconcat 'list "abc" "/")"a/b/c"
> 
> Maybe this helps clarify why that works:
> 
> (let (r)
>   (dolist (e (string-to-list "abc") r)
>     (setq r (concat r (if (null r) "" "/") (list e)))))
> 
> Steve Berman
> 
> 
> 
> 

Thanks. Assumed wrongly result type of mapconcat follows function applied.
But it's concat which defines the result type, as function name says...


Andreas




^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2010-03-04 15:07 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-03 12:49 problem with mapconcat Christian Wittern
2010-03-03 13:50 ` Dan Davison
2010-03-03 13:55   ` Christian Wittern
2010-03-03 13:57 ` Teemu Likonen
2010-03-03 15:23   ` Thamer Mahmoud
2010-03-03 15:41     ` Thamer Mahmoud
2010-03-04  1:39       ` Christian Wittern
2010-03-04  7:36       ` Andreas Röhler
2010-03-04  9:35         ` Stephen Berman
2010-03-04 15:07           ` Andreas Röhler
2010-03-04  6:56 ` Kevin Rodgers

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.