29 lines
824 B
Racket
29 lines
824 B
Racket
#lang racket/base
|
|
|
|
(require racket/contract racket/list racket/match)
|
|
|
|
(provide metadata? config? assoc-ref assoc-ref+)
|
|
|
|
(define metadata?
|
|
(listof (or/c
|
|
(list/c 'date integer? integer? integer?)
|
|
(list/c 'title string?)
|
|
(list/c 'lang string?)
|
|
(cons/c 'tags (listof string?))
|
|
(list/c 'summary string?)
|
|
(cons/c 'authors (listof string?)))))
|
|
|
|
(define config?
|
|
(listof (or/c
|
|
(list/c 'base string?))))
|
|
|
|
(define (assoc-ref md key [default (λ () (error "no such key"))])
|
|
(match (assoc key md)
|
|
[#f (if (procedure? default) (default) default)]
|
|
[(cons _ rst) rst]))
|
|
|
|
(define (assoc-ref+ md key [default (λ () (error "no such key"))])
|
|
(match (assoc key md)
|
|
[#f (if (procedure? default) (default) default)]
|
|
[(list _ snd) snd]))
|