| 1 | <h2>Full example</h2> |
| 2 | <pre><code>; Source: https://github.com/mbutterick/pollen/blob/master/pollen/private/to-string.rkt |
| 3 | |
| 4 | #lang racket/base |
| 5 | (provide (all-defined-out)) |
| 6 | |
| 7 | (define (to-string x) |
| 8 | (cond |
| 9 | [(string? x) x] |
| 10 | [(or (null? x) (void? x)) ""] |
| 11 | [(or (symbol? x) (number? x) (path? x) (char? x)) (format "~a" x)] |
| 12 | ;; special handling for procedures, because if a procedure reaches this func, |
| 13 | ;; it usually indicates a failed attempt to use a tag function. |
| 14 | ;; meaning, it's more useful to raise an error. |
| 15 | [(procedure? x) (error 'pollen "Can't convert procedure ~a to string" x)] |
| 16 | [else (format "~v" x)]))</code></pre> |