(import (chicken format)) ; format printf (import srfi-13) ; string-copy! (define (string-repeat str n) (let* ((slen (string-length str)) (res (make-string (* slen n)))) (do ((i 0 (+ i slen))) ((= i n) res) (string-copy! res i str)))) (define arrow "-->") (define spacer (string-repeat " " (string-length arrow))) (define (print-cell val) (printf "| ~a | *-|" val)) ;;; Convert any value to a string, a hack though (define (any->number val) (format #f "~a" val)) (define (print-top-bottom lst) (for-each (lambda (e) (let ((vals (any->number e))) (printf "+~a+---+~a" (string-repeat "-" (+ (string-length vals) 2)) spacer))) lst) (display "\n")) ;;; Creates a ASCII-art representation of a list (define (list-ascii lst) (print-top-bottom lst) (for-each (lambda (c) (print-cell c) (display arrow)) lst) (display "NIL\n") (print-top-bottom lst)) (list-ascii '(1 2 3 4)) (list-ascii '("foo" #x27 "aaaeeeiiiooouuu" 100 28/8))