;; A word generator designed for use in an interactive environment (define (fold-right f init seq) (if (null? seq) init (f (car seq) (fold-right f init (cdr seq))))) (define (pick-random lst) (let ((index (random (length lst)))) (list-ref lst index))) (define (C) (pick-random '("s" "v" "ch" "j"))) (define (V) (pick-random '("a" "e" "u"))) (define (N) (pick-random '("n" "l"))) (define (string->procs str) (define (randomize chars) (cond ((null? chars) '()) ((char=? (car chars) #\?) (if (zero? (random 2)) (cons (cadr chars) (randomize (cddr chars))) (randomize (cddr chars)))) (else (cons (car chars) (randomize (cdr chars)))))) (map (lambda (c) (eval (string->symbol (string c)))) (randomize (string->list str)))) (define (generate-word template) (apply string-append (map (lambda (f) (f)) (string->procs template)))) ;; Example: (generate-word "CVNVN") ;; => "jenel"