(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
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.
You could use the general map function:
(map 'string (lambda (char) (code-char (1+ (char-code char))))
"dummy string")
--
Howard Ding
<had...@att.net>
http://math.sunysb.edu/~hading http://thunder.prohosting.com/~hading
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.
> 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/>
In addition to the worthy advice already posted, see the
ACROSS clause of LOOP.
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
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
Check dovector in UTILS :)
sl