#lang racket
(struct pony (race name alist))
(define (unicorn name)
(pony 'unicorn name '()))
(define (pegasus name)
(pony 'pegasus name '()))
(define (earth-pony name)
(pony 'earth-pony name '()))
(define ponies
(list (unicorn "Twilight Sparkle")
(unicorn "Rarity")
(pegasus "Rainbow Dash")
(pegasus "Fluttershy")
(earth-pony "Pinkie Pie")
(earth-pony "Applejack")
(pony 'unicorn "Moon Dancer" '((best? . #t)))))
(define (is-multiword-name name)
(>= (length (string-split name " ")) 2))
(define pony-names
(map (lambda (x) (pony-name x)) ponies))
(define multiword-pony-names
(filter (lambda (x) (is-multiword-name x)) pony-names))
(define (best-pony? pony)
(if (assq 'best? (pony-alist pony))
#t
#f))
(define best-pony (car (memf best-pony? ponies)))