Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to write implode and explode?

14 views
Skip to first unread message

Robert L.

unread,
May 18, 2018, 7:23:38 PM5/18/18
to
Erik Naggum wrote:

> * Josh Gardner <jg...@dowco.com>
> | I'm stuck on a bit of a problem: I need to write an implode function -
> | takes '(H e l l o) and gives back 'Hello. and I need to write an explode
> | function - takes 'Hello and returns '(H e l l o)
>
> OK, so it's probably homework, yet here's what I'd do, but I'm certain
> that you won't be allowed to hand this in, anyway, so it's safe to give
> you this "answer".
>
> (defun explode (symbol)
> (map 'list (lambda (character) (intern (string character) #.*package*))
> (symbol-name symbol)))
>
> (defun implode (list)
> (intern (map 'string #'character list) #.*package*))


(define (explode sym)
(map string->symbol (map string (string->list (symbol->string sym)))))

> (explode 'jux)
'(j u x)

(define (implode syms)
(string->symbol (apply ~a syms)))

> (implode '(j u x))
'jux


--
[E]verything that happens in the world is for the benefit of the Jewish
People.... G-D ... created the world for the sake of the Jewish People, and it
is our responsibility to implement the Torah---absolute morality and the
blueprint of creation---in it. http://archive.org/details/nolies
0 new messages