[racket] Super basic question about strings
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)
(string-append
(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))))