2021-06-07 09:09:20 +00:00
|
|
|
#lang racket/base
|
|
|
|
|
|
|
|
(require racket/contract racket/list racket/match)
|
|
|
|
|
2021-06-11 08:00:42 +00:00
|
|
|
(provide metadata? config? assoc-ref assoc-ref+)
|
2021-06-07 09:09:20 +00:00
|
|
|
|
|
|
|
(define metadata?
|
|
|
|
(listof (or/c
|
|
|
|
(list/c 'date integer? integer? integer?)
|
|
|
|
(list/c 'title string?)
|
2021-06-10 23:45:14 +00:00
|
|
|
(list/c 'lang string?)
|
2021-06-08 05:20:14 +00:00
|
|
|
(cons/c 'tags (listof string?))
|
2021-06-07 09:09:20 +00:00
|
|
|
(list/c 'summary string?)
|
|
|
|
(cons/c 'authors (listof string?)))))
|
|
|
|
|
2021-06-11 08:00:42 +00:00
|
|
|
(define config?
|
|
|
|
(listof (or/c
|
|
|
|
(list/c 'base string?))))
|
|
|
|
|
|
|
|
(define (assoc-ref md key [default (λ () (error "no such key"))])
|
2021-06-07 09:09:20 +00:00
|
|
|
(match (assoc key md)
|
|
|
|
[#f (if (procedure? default) (default) default)]
|
|
|
|
[(cons _ rst) rst]))
|
|
|
|
|
2021-06-11 08:00:42 +00:00
|
|
|
(define (assoc-ref+ md key [default (λ () (error "no such key"))])
|
2021-06-10 23:45:14 +00:00
|
|
|
(match (assoc key md)
|
|
|
|
[#f (if (procedure? default) (default) default)]
|
|
|
|
[(list _ snd) snd]))
|