Subject: Re: A list 'explode" function
From: rpw3@rpw3.org (Rob Warnock)
Date: Sat, 19 Mar 2005 06:18:46 -0600
Newsgroups: comp.lang.lisp
Message-ID: <QYmdnZNv9ag7haHfRVn-sw@speakeasy.net>
David Golden  <david.golden@oceanfree.net> wrote:
+---------------
| I do think there should be a standardised "SEXPLODE" function to
| convert a symbol such as MAKE-ROCKET-GO-NOW into a list of smaller
| symbols '(MAKE ROCKET GO NOW)  
+---------------

What's so hard about that?   ;-}

    > (asdf:operate 'asdf:load-op :split-sequence)
    ...[chatter]...

    > (import 'split-sequence:split-sequence)

    T
    > (defun sexplode (symbol)
        (mapcar #'intern (split-sequence #\- (symbol-name symbol))))  

    SEXPLODE
    > (sexplode 'make-rocket-go-now)

    (MAKE ROCKET GO NOW)
    > 

Oh, you mean it doesn't "do the right thing" with packages?

    > (make-package :foo :use nil)

    #<The FOO package, 0/9 internal, 0/9 external>
    > (sexplode 'foo::make-rocket-go-now)

    (MAKE ROCKET GO NOW)
    > 

We can fix that:  ;-}

    > (defun sexplode (symbol &optional (package (symbol-package symbol)))
	(flet ((re-intern (string)
		 (intern string package)))
	  (mapcar #'re-intern (split-sequence #\- (symbol-name symbol)))))

    SEXPLODE
    > (sexplode 'foo::make-rocket-go-now)

    (FOO::MAKE FOO::ROCKET FOO::GO FOO::NOW)
    >

and:

    > (sexplode 'make-rocket-go-now :foo)

    (FOO::MAKE FOO::ROCKET FOO::GO FOO::NOW)
    > 


-Rob

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607