[racket] Super basic question about strings

From: namekuseijin (namekuseijin at gmail.com)
Date: Wed Nov 17 10:06:53 EST 2010

On Wed, Nov 17, 2010 at 5:34 AM, Richard Lawrence
<richard.lawrence at berkeley.edu> wrote:
> Dear Racketeers:
> For example, suppose I want to consume an association list like
>  '((k1 . v1) (k2 . v2) ...)
> and produce a string that looks like:
>  "k1=v1 k2=v2 ..."

(join " "
      (map (lambda (kv)
              (symbol->string (car kv))
              (symbol->string (cdr kv))))
           '((k1 . v1) (k2 . v2) (k3 . v3))))

; given
(define (fold f o ls)
  (if (null? ls) o
      (fold f (f (car ls) o) (cdr ls))))

(define (join s ls)
  (if (null? ls) ""
      (fold (lambda (i o) (string-append o s i)) (car ls) (cdr ls))))

Posted on the users mailing list.