Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!think!barmar From: barmar@think.COM (Barry Margolin) Newsgroups: comp.lang.lisp Subject: Re: explode macro/function for SUN cl Message-ID: <36368@think.UUCP> Date: 13 Feb 89 20:40:34 GMT References: <4257@pt.cs.cmu.edu> Sender: news@think.UUCP Reply-To: barmar@kulla.think.com.UUCP (Barry Margolin) Organization: Thinking Machines Corporation, Cambridge, MA Lines: 48 In article <4257@pt.cs.cmu.edu> jwz@spice.cs.cmu.edu (Jamie Zawinski) writes: >EXPLODE could be implemented as [code deleted] >This means that INTERN will be called for every element of the >namestring of the symbol, which will do a hash-table-store. While I agree with everything else you said, I have one question: why are you INTERNing the symbols? For the purposes of EXPLODE and IMPLODE, uninterned symbols should probably work. Actually, it really depends on how the caller plans on using the list. I suspect that the requester knows that this is not the right way to do what he's doing. My guess is he's trying to port some old Franz Lisp code to Common Lisp, and it makes use of EXPLODE. By the way, the function requested (and which you implemented) is closer to MacLisp's EXPLODEC than EXPLODE. EXPLODE in MacLisp returns a list of the characters making up the object's printed representation. It works on any object, and it includes the slashes. It could be defined as: (defun explode (object &optional (intern-p t)) (let ((string (prin1-to-string object)) (result nil) (one-char-string (make-string 1))) (map 'list #'(lambda (char) (setf (char one-char-string 0) char) (if intern-p (intern one-char-string) (make-symbol one-char-string)))))) I added the INTERN-P optional argument to allow interning to be disabled. MacLisp EXPLODEC would be the same, except PRIN1-TO-STRING would be replaced with PRINC-TO-STRING. Note also the reuse of ONE-CHAR-STRING in my definition. I think this is about as efficient as one can get using only standard Common Lisp. Unfortunately there is still the string containing the printed representation; if Common Lisp had a way to define streams, you could implement a stream that took the characters and collected them into a immediately. Barry Margolin Thinking Machines Corp. barmar@think.com {uunet,harvard}!think!barmar