Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!rochester!pt.cs.cmu.edu!spice.cs.cmu.edu!jwz From: jwz@spice.cs.cmu.edu (Jamie Zawinski) Newsgroups: comp.lang.lisp Subject: Re: explode macro/function for SUN cl Message-ID: <4257@pt.cs.cmu.edu> Date: 13 Feb 89 01:47:54 GMT Organization: Carnegie-Mellon University, CS/RI Lines: 40 Jerry B. Altzman writes: > Does anyone out there have an explode macro or function? I would say that if you want to use EXPLODE/IMPLODE, then you're almost certainly not taking advantage of the language. This is what strings are for; EXPLODE/IMPLODE are leftovers from early Lisps which did not have strings. Say you want to get the first character of a symbol - you could do this with (char (symbol-name symbol) 0) or with (car (explode symbol)) The former will return a character object, which is likely stored as an immediate quantity. The latter will return a pointer to a symbol, which is a data structure of five slots, including a string of its name; also, symbols are entered in a package hash table, which adds some more overhead. EXPLODE could be implemented as (defun explode (sym) (let ((list '()) (string (symbol-name sym))) (dotimes (i (length string)) (push (intern (string (char string i))) list)) (nreverse list))) This means that INTERN will be called for every element of the namestring of the symbol, which will do a hash-table-store. Also, INTERN must be called with a string, so a number of one-character strings are created as well. Finally, a list is consed. So it's a real lose; anything else would be more efficient. Read the chapter of "Common Lisp: the Language" on sequence functions; there are a plethora of functions that operate on strings and arrays as well as lists. Jamie Zawinski jwz@spice.cs.cmu.edu sun!sunpitt!eti!jwz --