From: John Slimick
Subject: explode
Date: 
Message-ID: <slrnb4dkio.m1i.slimick@jcs.upb.pitt.edu>
Hello:

Once upon a time there was a LISP function
"explode" that exploded a string thus:

  (explode "fatcat") = ("f" "a" "t" "c" "a" "t")

(or maybe it just worked on atom names -- I can't
really remember -- and was there an implode that put
the string back together?).

How do we do this now? I looked in the hyperpaedia,
but I could not find anything.

Thanks in advance

john slimick
·······@pitt.edu

From: Nils Goesche
Subject: Re: explode
Date: 
Message-ID: <87fzqxozqp.fsf@darkstar.cartan>
·······@jcs.upb.pitt.edu (John Slimick) writes:

> Once upon a time there was a LISP function
> "explode" that exploded a string thus:
> 
>   (explode "fatcat") = ("f" "a" "t" "c" "a" "t")
> 
> (or maybe it just worked on atom names -- I can't really
> remember -- and was there an implode that put the string back
> together?).
> 
> How do we do this now? I looked in the hyperpaedia, but I could
> not find anything.

You could use MAP or COERCE.

CL-USER 4 > (map 'list #'string "foobar")
("f" "o" "o" "b" "a" "r")

CL-USER 5 > (coerce "foobar" 'list)
(#\f #\o #\o #\b #\a #\r)

Regards,
-- 
Nils G�sche
Ask not for whom the <CONTROL-G> tolls.

PGP key ID #xD26EF2A0
From: Jeremy Yallop
Subject: Re: explode
Date: 
Message-ID: <b26lof$19ek8t$1@ID-114079.news.dfncis.de>
Nils Goesche wrote:
> ·······@jcs.upb.pitt.edu (John Slimick) writes:
> 
>> Once upon a time there was a LISP function
>> "explode" that exploded a string thus:
>> 
>>   (explode "fatcat") = ("f" "a" "t" "c" "a" "t")
>> 
>> (or maybe it just worked on atom names -- I can't really
>> remember -- and was there an implode that put the string back
>> together?).
>> 
>> How do we do this now? I looked in the hyperpaedia, but I could
>> not find anything.
> 
> You could use MAP or COERCE.
> 
> CL-USER 4 > (map 'list #'string "foobar")
> ("f" "o" "o" "b" "a" "r")
> 
> CL-USER 5 > (coerce "foobar" 'list)
> (#\f #\o #\o #\b #\a #\r)

Or LOOP:

  > (loop for c across "foobar" collecting c)
  (#\f #\o #\o #\b #\a #\r)

  > (loop for c across "foobar" collecting (string c))
  ("f" "o" "o" "b" "a" "r")

COERCE or CONCATENATE will put it back together:

  > (coerce '(#\f #\o #\o #\b #\a #\r) 'string)
  "foobar"

  > (apply #'concatenate 'string '("f" "o" "o" "b" "a" "r"))
  "foobar"

Jeremy.
From: Matthew Danish
Subject: Re: explode
Date: 
Message-ID: <20030210005426.A562@lain.cheme.cmu.edu>
On Sun, Feb 09, 2003 at 10:46:39PM +0000, Jeremy Yallop wrote:
>   > (apply #'concatenate 'string '("f" "o" "o" "b" "a" "r"))
>   "foobar"

Not a good idea; you might exceed call-arguments-limit using APPLY like
so.  How about:

 (reduce #'(lambda (a b) (concatenate 'string a b)) 
         '("f" "o" "o" "b" "a" "r"))

or

 (format nil "~{~A~}" '("f" "o" "o" "b" "a" "r"))

-- 
; Matthew Danish <·······@andrew.cmu.edu>
; OpenPGP public key: C24B6010 on keyring.debian.org
; Signed or encrypted mail welcome.
; "There is no dark side of the moon really; matter of fact, it's all dark."
From: Rahul Jain
Subject: Re: explode
Date: 
Message-ID: <874r7d6nj3.fsf@localhost.localdomain>
·······@jcs.upb.pitt.edu (John Slimick) writes:

> Hello:
> 
> Once upon a time there was a LISP function
> "explode" that exploded a string thus:
> 
>   (explode "fatcat") = ("f" "a" "t" "c" "a" "t")

(explode 'fatcat) = (#\F #\A #\T ..)

> How do we do this now? I looked in the hyperpaedia,
> but I could not find anything.

Hyperspec maybe? We have strings these days. Why do you need to treat
symbols as non-symbolic objects? SYMBOL-NAME and COERCE may be what you
are looking for, if you KNOW you want to do it this way.

-- 
Rahul Jain
From: Wolfhard Buß
Subject: Re: explode
Date: 
Message-ID: <m31y2elubu.fsf@buss-14250.user.cis.dfn.de>
·······@jcs.upb.pitt.edu (John Slimick) writes:
>
> Once upon a time there was a LISP function
> "explode" that ...

Once upon a time there was a Lisp function EXPLODE that `results in a
list of the characters which would be printed by PRINT'.
Lispniks may know that EXPLODE was written by William A. Martin and is
described in "A New Version of CTSS LISP" by Robert R. Fenichel and
Joel Moses, published as MIT AI Memo No. 93 on 2. Feb. 1966.
EXPLODE was also part of MacLisp and Zetalisp. EXPLODE in Common Lisp 
might look like

 (defun explode (object)
   (let ((*print-pretty* nil))
     (coerce (prin1-to-string object) 'list)))

> and was there an implode that put the string back together?

READLIST was the inverse of EXPLODE. IMPLODE was something like

 (defun implode (char-list)
   (intern (coerce char-list 'string)))

Interlisp had PACK and UNPACK with similar semantics.

You might also look at the Lisp FAQ subject [2-3]: `What is the
equivalent of EXPLODE and IMPLODE in Common Lisp?'


-- 
"Hurry if you still want to see something. Everything is vanishing."
                                       --  Paul C�zanne (1839-1906)