Dealing with functions which may return values of different types

Not @sorawee, obviously, but since you asked about the #; in another thread, I thought it might be interesting to show off some of Racket's other interesting "reader magic":

(define (initial-create str)
  (define o-neal (regexp-match #px".*?'([^']{1})" str))
  (cond [o-neal (car o-neal)]
        [else
         (define stub            (name-prefix str))
         (define |str without '| (string-replace str "'" ""))
         (cond [(equal? stub |str without '|)
                (string-upcase (substring str 0 1))]
               [else stub])]))

The interesting part here, is |str without '|, which is a delimited sequence of characters which can be referenced, for example, like any other identifier.

2 Likes