From: Ulf Sundin
Subject: Implode, explode and Common Lisp
Date: 
Message-ID: <1840@chalmers.UUCP>
I intend to translate a rather large Franz Lisp program
to Common Lisp. However, some parts of the progeram relies
heavily on the use of 'implode' and 'explode' for which
no equivalents are defined in Common Lisp.

What is needed is thus the following functions:
(in Common Lisp)

  (implode 'l_arg)

where l_arg is assumed to be a list of symbols (and strings).
The function should return the symbol whose printname
is the result of concatenating the first characters
of the print names of the symbols.

If it facilitates the solution, you may assume that the list
l_arg only contains 1-characther symbols.

  (explode 'g_arg)

returning a list of the characters used to print g_arg.

The simpler function

  (aexplode 's_arg)

which only accepts a symbol as an argument
may also be useful.


Ulf Sundin
Chalmers University of Tech, Sweden
...mcvax!enea!chalmers!sundin

From: Gordon E. Banks
Subject: Re: Implode, explode and Common Lisp
Date: 
Message-ID: <771@cadre.dsl.PITTSBURGH.EDU>
In article <····@chalmers.UUCP> ······@chalmers.UUCP (Ulf Sundin) writes:
>I intend to translate a rather large Franz Lisp program
>to Common Lisp. However, some parts of the progeram relies
>heavily on the use of 'implode' and 'explode' for which
>no equivalents are defined in Common Lisp.
>
This seems to work for me, but I'm no Lisp expert.


(defun explode (atom-name)
  "Explodes the atom name into a list of characters."
  (coerce (string atom-name) 'list))

(defun implode (charlist)
  "Given a list of characters, returns an imploded atom name."
  (intern (coerce charlist 'string)))

If you have a better solution, let me know, since I use these a lot.
From: Barry Margolin
Subject: Re: Implode, explode and Common Lisp
Date: 
Message-ID: <7299@think.UUCP>
In article <···@cadre.dsl.PITTSBURGH.EDU> ···@cadre.dsl.pittsburgh.edu.UUCP (Gordon E. Banks) writes:
>(defun explode (atom-name)
>  "Explodes the atom name into a list of characters."
>  (coerce (string atom-name) 'list))
>
>(defun implode (charlist)
>  "Given a list of characters, returns an imploded atom name."
>  (intern (coerce charlist 'string)))

These don't fit the poster's specifications.  He said that CHARLIST is
a list of symbols and strings, but your IMPLODE expects a sequence of
characters.  Here are versions that I think are completely compatible
with Maclisp.

(defun implode (charlist)
  (intern (map 'string #'character charlist)))

;;; This is more complex because EXPLODE isn't restricted to symbols
(defun explode (object &aux (str (make-string 1)))
  (map 'list #'(lambda (char)
		  (setf (aref str 0) char)
		   (intern str))
       (with-output-to-string (s)
	 (prin1 object s))))

---
Barry Margolin
Thinking Machines Corp.

······@think.com
seismo!think!barmar
From: Jeff Dalton
Subject: Re: Implode, explode and Common Lisp
Date: 
Message-ID: <138@aiva.ed.ac.uk>
In article <····@chalmers.UUCP> ······@chalmers.UUCP (Ulf Sundin) writes:
> I intend to translate a rather large Franz Lisp program
> to Common Lisp. However, some parts of the progeram relies
> heavily on the use of 'implode' and 'explode' for which
> no equivalents are defined in Common Lisp.

I wrote the following code a while ago and have used it with some
success.  

;;; Implode, explode, and friends
;;;
;;; Jeff Dalton, AIAI, University of Edinburgh
;;;
;;; In Franz, a character can be represented by either (1) a symbol with
;;; that character as the first character of its print name, or (2) the
;;; (ascii) value of that character as a fixnum.  So we have to handle
;;; all of these.  Actually, we accept only symbols with one character
;;; in their print name.
;;;
;;; Coercion and conversion in Common Lisp can be a pain because it is
;;; not always clear which function will do the trick.  For example,
;;; (coerce #\a 'string) is an error; you have to use (string #\a).
;;;  For some reason, the powers of 'string' and 'coerce' are reversed
;;; for sequences: 'string' applied to a sequence of characters gives
;;; an error, but 'coerce' will in fact coerce it.
;;;
;;; Note: we use the '->' convention for naming conversion functions
;;; (a la T).


;;; conversions to Franz forms

(defun char->fixnum (ch) (char-code ch))	;ignore bits and font

(defun char->symbol (ch) (intern (string ch)))  ;assumes *package* is OK


;;; conversions from Franz forms

(defun franz-char->char (fch)
  ;; works for all the cases we need, and for single-char strings.
  (coerce fch 'character))


;;; the Franz functions

(defun explode (x)
  (map 'list #'char->symbol (prin1-to-string x)))
  
(defun aexplode (x) (explode x))

(defun explodec (x)
  (map 'list #'char->symbol (princ-to-string x)))

(defun aexplodec (x) (explodec x))

(defun exploden (x)
  (map 'list #'char->fixnum (princ-to-string x)))

(defun aexploden (x) (exploden x))

(defun implode (x)
  (intern
   (map 'string #'franz-char->char x)))

(defun maknam (x)
  (make-symbol
   (map 'string #'franz-char->char x)))

(defun printlist (x) (explode x))	;not actually in Franz?

(defun readlist (x)			;seldom used?
  (read-from-string
   (map 'string #'franz-char->char x)))


;;;; Other Character and String operations

(defun getchar (symbol-or-string n)
  (char->symbol (schar (string symbol-or-string) (1- n))))

(defun nthchar (x n) (getchar x n))

(defun getcharn (symbol-or-string n)
  (char->fixnum (schar (string symbol-or-string) (1- n))))

(defun concat (x y &rest more-args)
  (intern
   (apply #'concatenate 'string
	  (string x) (string y) (mapcar #'string more-args))))


Jeff Dalton,                          JANET: ········@uk.ac.ed             
AI Applications Institute,            ARPA:  ·················@cs.ucl.ac.uk
Edinburgh University.                 UUCP:  ...!ukc!ed.ac.uk!J.Dalton
From: Sean McLinden
Subject: Re: Implode, explode and Common Lisp
Date: 
Message-ID: <776@cadre.dsl.PITTSBURGH.EDU>
In article <····@chalmers.UUCP> ······@chalmers.UUCP (Ulf Sundin) writes:
>I intend to translate a rather large Franz Lisp program
>to Common Lisp. However, some parts of the progeram relies
>heavily on the use of 'implode' and 'explode' for which
>no equivalents are defined in Common Lisp.
>

The functions "implode" and "explode" were needed in Franz because there
was no concept of a "sequence" in Franz Lisp. What you want to do is trivial
if you think of the symbol name of an object as a sequence. Check the
section on Sequences in Steele's book for ideas.

Sean McLinden
Decision Systems Laboratory
University of Pittsburgh