capybara/defs.rkt

29 lines
824 B
Racket
Raw Normal View History

2021-06-07 09:09:20 +00:00
#lang racket/base
(require racket/contract racket/list racket/match)
(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?)
(cons/c 'tags (listof string?))
2021-06-07 09:09:20 +00:00
(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"))])
2021-06-07 09:09:20 +00:00
(match (assoc key md)
[#f (if (procedure? default) (default) default)]
[(cons _ rst) rst]))
(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]))