Newsgroups: comp.lang.scheme Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!rice!tone.rice.edu!dorai From: dorai@tone.rice.edu (Dorai Sitaram) Subject: Re: Explode/Implode Query Message-ID: <1991Apr22.215944.19625@rice.edu> Sender: news@rice.edu (News) Organization: Rice University, Houston References: <1991Apr22.180734.21661@cunixf.cc.columbia.edu> Date: Mon, 22 Apr 91 21:59:44 GMT In article raja@copper.ucs.indiana.edu (Raja Sooriamurthi) writes: >But you can define these function yourself in any R3.99 scheme as >below: > >; (explode 'apple) => (a p p l e) >; (implode '(a p p l e)) => apple >; (eq? 'apple (implode (explode 'apple))) => #t > > [perfectly reasonable Scheme "interpretations" of explode and implode deleted] You have "typed" explode and implode to go between symbols and single-char symbols. However, the way I remember it, the following were quite legal. (explode 'apple2) => (a p p l e 2) ;;; not (... |2|) (implode '(a p p l e 2)) => apple2 (explode 42) => (4 2) ;;; not (|4| |2|) (implode '(4 2)) => 42 ;;; not |42| Indeed, I think I remember seeing explode even take on lists!! E.g., (explode '(apple 2)) => (|(| a p p l e | | 2 |)|) An unsatisfactory first attempt at getting something like this in Ch*z -- or a Scheme with stringports -- would be (define digit-or-single-char-symbol (let ([zero (char->integer #\0)]) (lambda (c) (if (and (char>=? c #\0) (char<=? c #\9)) (- (char->integer c) zero) (string->symbol (format "~a" c)))))) (define explode (lambda (x) (map digit-or-single-char-symbol (string->list (format "~a" x))))) (define implode (lambda (s) (let ([p (open-input-string (apply string-append (map (lambda (c) (format "~a" c)) s)))]) (begin0 (read p) (close-input-port p))))) This is unsatisfactory, since you'll have to do some more work to get the second half of the following working: (explode '|apple 2|) => (a p p l e | | 2) (implode '(a p p l e | | 2)) => |apple 2| ;;; not apple --d