(define ranks '(a k q j 10 9 8 7 6 5 4 3 2))
(define suits '(s h d c))

(define (numeric-rank card)
  (let ((r (rank card)))
   (cond ((equal? r 'a) 14)
         ((equal? r 'k) 13)
         ((equal? r 'q) 12)
         ((equal? r 'j) 11)
         (else r))))

(define (make-card suit rank)
   (word suit rank))
(define (rank card) (bf card))
(define (suit card) (first card))

(define (sort hand)
   ((repeated sort-once (- (count hand) 1)) hand))

(define (sort-once hand)
   (cond ((empty? hand) hand)
         ((= (count hand) 1) hand)
         ((> (numeric-rank (first hand))
             (numeric-rank (first (bf hand))))
                 (se (first hand) (sort-once (bf hand))))
         (else (se (first (bf hand))
                   (sort-once (se (first hand) (bf (bf hand))))))))

(define (poker-value hand)
  (let ((sortedhand (sort hand)))
    (cond ((royal-flush? sortedhand) ??)
          ((straight-flush? sortedhand) ??)
          ((four-of-a-kind? sortedhand) ??)
          ((full-house? sortedhand) ??)
          ((flush? sortedhand) ??)
          ((straight? sortedhand) ??)
          ((three-of-a-kind? sortedhand) ??)
          ((two-pair? sortedhand) ??)
          ((pair? sortedhand) ??)
          (else ??))))