From: Allan M. Bernstein
Subject: Please help common lisp
Date: 
Message-ID: <33BA766B.942F6379@higfhfiber.com>
How do I write a function that will recieve  000156 and return '(0 0 0 1
5 6) ?
From: Dave Seaman
Subject: Re: Please help common lisp
Date: 
Message-ID: <5pe4jr$9mv@seaman.cc.purdue.edu>
In article <·················@higfhfiber.com>,
Allan M. Bernstein <····@highfiber.com> wrote:
>How do I write a function that will recieve  000156 and return '(0 0 0 1
>5 6) ?

Maybe it would help if you explained what you really want to do.  For
one thing, 000156 is just the number 156.  The leading zeroes are
ignored by the reader.  If you really want to include leading zeroes,
you probably want either a symbol
	
	'|000156|

or a string

	"000156"

rather than a number.  You can convert easily from one to the other:

	(symbol-name '|000156|)	=>	"000156"
	(make-symbol "000156")	=>	#:|000156|

where the result of make-symbol is an uninterned symbol.  It's not
clear to me that a list of numbers would be easier to work with here
than a string (a vector of chars), but I suppose you could define
something like

  (defun explode (symbol)
    "Convert a symbol to a list of one-character atoms"
    (loop with name = (symbol-name symbol)
	  for p below (length name)
	  collect (read-from-string name nil nil :start p :end (1+ p))))

after which you have

	(explode '|000156|)	=> (0 0 0 1 5 6)
	(explode 'all41&14all)	=> (a l l 4 1 & 1 4 a l l)

but note that this may be unnecessarily complicated.  You should look
at some other functions on strings, such as

	(coerce "all41" 'list)	=> (#\a #\l #\l #\4 #\1)

which allows you to convert arbitrary vectors into lists, or

	(char "all41" 3)	=> #\4	

which accesses the third character of a string, where the count begins
at zero.  Perhaps one of these will do what you really want without the
overhead of the EXPLODE function.

-- 
Dave Seaman			·······@purdue.edu
      ++++ stop the execution of Mumia Abu-Jamal ++++
    ++++ if you agree copy these lines to your sig ++++
++++ see http://www.xs4all.nl/~tank/spg-l/sigaction.htm ++++