From: Alexander Schofield
Subject: iterating over string
Date: 
Message-ID: <3C670B7C.700755F7@mailhost.njit.edu>
What is a better way of iterating over strings a char at a time?  Say a
better way to produce the same result below:

(setq str "dummy string")

(coerce (let ((chlist (coerce str 'list)))
  (mapcar (lambda (ch) (code-char (1+ (char-code ch))))
          chlist)) 'string)

#=> "evnnz!tusjoh"

TIA
-- 
Alexander Schofield

From: Erik Naggum
Subject: Re: iterating over string
Date: 
Message-ID: <3222374784030396@naggum.net>
* Alexander Schofield <····@mailhost.njit.edu>
| What is a better way of iterating over strings a char at a time?

  See the function map in the hyperspec.

///
-- 
  In a fight against something, the fight has value, victory has none.
  In a fight for something, the fight is a loss, victory merely relief.
From: Howard Ding
Subject: Re: iterating over string
Date: 
Message-ID: <3C670B0D.100855EB@att.net>
> 
> (setq str "dummy string")
> 
> (coerce (let ((chlist (coerce str 'list)))
>   (mapcar (lambda (ch) (code-char (1+ (char-code ch))))
>           chlist)) 'string)
> 
> #=> "evnnz!tusjoh"

You could use the general map function:

(map 'string (lambda (char) (code-char (1+ (char-code char)))) 
     "dummy string")

-- 
Howard Ding
<······@att.net>
http://math.sunysb.edu/~hading  http://thunder.prohosting.com/~hading
From: Christopher C. Stacy
Subject: Re: iterating over string
Date: 
Message-ID: <u6654zkvn.fsf@theworld.com>
>>>>> On Sun, 10 Feb 2002 19:08:29 -0500, Alexander Schofield ("Alexander") writes:

 Alexander> What is a better way of iterating over strings a char at a time?  Say a
 Alexander> better way to produce the same result below:

 Alexander> (setq str "dummy string")

 Alexander> (coerce (let ((chlist (coerce str 'list)))
 Alexander>   (mapcar (lambda (ch) (code-char (1+ (char-code ch))))
 Alexander>           chlist)) 'string)

 Alexander> #=> "evnnz!tusjoh"

A string is one of the "sequence" data types in Lisp, so there's 
no need to convert it into a list.  The elements in the string
are characters, and there's generally no need to convert them back 
and forth into their numeric codes (although that's appropriate
given what your example function accomplishes).

Read the "Sequences" chapter in the Common Lisp HyperSpec,
in particular the function MAP.   You might also like to
read about the LOOP macro in the "Iteration" chapter,
especially the "for-as-across" subclause.
MAP includes the functionality of COERCE.
From: Dr. Edmund Weitz
Subject: Re: iterating over string
Date: 
Message-ID: <m3heooim3z.fsf@bird.agharta.de>
Alexander Schofield <····@mailhost.njit.edu> writes:

> What is a better way of iterating over strings a char at a time?
> Say a better way to produce the same result below:

<http://agharta.de/cookbook/strings.html#process>

Edi.

-- 

Dr. Edmund Weitz
Hamburg
Germany

The Common Lisp Cookbook
<http://agharta.de/cookbook/>
From: Steven M. Haflich
Subject: Re: iterating over string
Date: 
Message-ID: <3C68A0AB.56A0E70C@pacbell.net>
Alexander Schofield wrote:
> 
> What is a better way of iterating over strings a char at a time?  Say a
> better way to produce the same result below:

In addition to the worthy advice already posted, see the
ACROSS clause of LOOP.
From: Jeff Sandys
Subject: Re: iterating over string
Date: 
Message-ID: <3C697C21.EAFF1A38@juno.com>
I like loop - across,

LISP(46): (setq str "dummy string")
"dummy string"
LISP(47): (loop
            :for ch :across str
            :collect (code-char (1+ (char-code ch))) :into str-out
            :finally (return (coerce str-out 'string)))
"evnnz!tusjoh"

Thanks,
Jeff Sandys


"Steven M. Haflich" wrote:
> 
> Alexander Schofield wrote:
> >
> > What is a better way of iterating over strings a char at a time?  Say a
> > better way to produce the same result below:
> 
> In addition to the worthy advice already posted, see the
> ACROSS clause of LOOP.
From: Steve Long
Subject: Re: iterating over string
Date: 
Message-ID: <3C69AAA9.A2AC34C1@hotmail.com>
Jeff,

Check dovector in UTILS  :)

sl

Jeff Sandys wrote:

> I like loop - across,
>
> LISP(46): (setq str "dummy string")
> "dummy string"
> LISP(47): (loop
>             :for ch :across str
>             :collect (code-char (1+ (char-code ch))) :into str-out
>             :finally (return (coerce str-out 'string)))
> "evnnz!tusjoh"
>
> Thanks,
> Jeff Sandys
>
> "Steven M. Haflich" wrote:
> >
> > Alexander Schofield wrote:
> > >
> > > What is a better way of iterating over strings a char at a time?  Say a
> > > better way to produce the same result below:
> >
> > In addition to the worthy advice already posted, see the
> > ACROSS clause of LOOP.
From: Nils Goesche
Subject: Re: iterating over string
Date: 
Message-ID: <a4bvv3$1dj8t7$2@ID-125440.news.dfncis.de>
In article <·················@juno.com>, Jeff Sandys wrote:
> I like loop - across,
> 
> LISP(46): (setq str "dummy string")
> "dummy string"
> LISP(47): (loop
>             :for ch :across str
>             :collect (code-char (1+ (char-code ch))) :into str-out
>             :finally (return (coerce str-out 'string)))
> "evnnz!tusjoh"

But at least look again at

(map 'string (lambda (c) ...

Regards,
-- 
Nils Goesche
"Don't ask for whom the <CTRL-G> tolls."

PGP key ID 0x42B32FC9