Subject: Re: Implode and explode with drscheme
From: rpw3@rigden.engr.sgi.com (Rob Warnock)
Date: 1999/06/23
Newsgroups: comp.lang.scheme
Message-ID: <7kpn0v$10v0v@fido.engr.sgi.com>
Fernando <spamers@must.die> wrote:
+---------------
| How can you implement those function with drscheme? O:-)  I've been
| playing around with the xxx->xxx functions, but haven't been succesful...
+---------------

Well, try adding "map" and maybe "apply" and "string-append" to the
various "XXX->YYY" functions, and it should be fairly straightforward:

	> (define (explode sym)
	    #| definition suppressed to avoid homework spoiler |# )
	> (define (implode syms)   
	    #| definition suppressed to avoid homework spoiler |# )
	> (implode '(t h i s t h a t o t h e r)) 
	thisthatother
	> (explode 'thisthatother)
	(t h i s t h a t o t h e r)
	>

That version provides the ability to do the following (which some might
consider to be an "error", however):

	> (implode '(this that other))
	thisthatother
	> (explode (implode '(this that other)))
	(t h i s t h a t o t h e r)
	>

If you want to prevent this, replace the "(apply string-append ...)"
in "implode" with "(apply string (map (lambda (x) (string-ref x 0)) ...))"
and you'll get this behavior instead:

	> (implode1 '(t h i s t h a t o t h e r)) 
	thisthatother
	> (implode1 '(this that other))
	tto
	> 


-Rob

-----
Rob Warnock, 8L-855		rpw3@sgi.com
Applied Networking		http://reality.sgi.com/rpw3/
Silicon Graphics, Inc.		Phone: 650-933-1673
1600 Amphitheatre Pkwy.		FAX: 650-933-0511
Mountain View, CA  94043	PP-ASEL-IA