Hi XLISP'S EXPERTS,
I was wondering if any expert could help me with a problem.
My problem is to write a function the will explode a string into a lisp..
Example: (explode 'WHAT)
Result: (W H A T)
Thanks in advance
Y. M. Pham
In article <····@copper.Denver.Colorado.EDU> ······@ouray (--== PHA.M ==--) writes:
>Hi XLISP'S EXPERTS,
>
> I was wondering if any expert could help me with a problem.
>My problem is to write a function the will explode a string into a lisp..
>
>Example: (explode 'WHAT)
>Result: (W H A T)
This should work for string s
(let ((result nil))
(dotimes (i (length s))
(setq result
(cons (intern (string (char s i))) result)))
(reverse result))
BTW, 'WHAT isn't a string, it's an atom. You might be able to make it
into one via (string 'WHAT).
--
! Peter Dudey, 11 kyu, Lisp SubGuru, Order of the Golden Parentheses \FINGER !
! Reformed Church of James "Eric" the Half-a-Bee, Dipped in Curry \ME !
! "A shadowy flight into the dangerous world of a man who does not exist." !
! Please mail me plastic spaceships: 900 State St. C-210, Salem, OR 97301 !
In article <····@copper.Denver.Colorado.EDU> ······@ouray (--== PHA.M ==--) writes:
>Hi XLISP'S EXPERTS,
FYI, there is comp.lang.lisp.x for XLISP specific questions.
> I was wondering if any expert could help me with a problem.
>My problem is to write a function the will explode a string into a lisp..
>Example: (explode 'WHAT)
>Result: (W H A T)
Well, it looks like you want to explode the printed representation of an
atom, and not a string. At any rate, here is the definition for the
standard lisp (but not Common Lisp) function EXPLODE, and the inverse
function IMPLODE. It is intended for XLISP-PLUS (Xlisp 2.1a, 2.1b, etc)
and defines a few additional Common Lisp functions.
(defun read-from-string (arg)
(read (make-string-input-stream arg)))
(defun character (arg) (coerce arg 'character))
(defun prin1-to-string (arg) (format nil "~s" arg))
(defun implode (list)
(read-from-string (coerce (mapcar #'character list) 'string)))
(defun explode (obj)
(map 'list #'(lambda (char)
(intern (string char)))
(prin1-to-string obj)))
--
Tom Almy
········@tek.com
Standard Disclaimers Apply