remove listof contracts

pull/58/head
Matthew Butterick 10 years ago
parent 4451e07a31
commit 9113efc72e

@ -3,6 +3,7 @@
(require "debug.rkt" "world.rkt") (require "debug.rkt" "world.rkt")
(define (symbols? x) (and (list? x) (andmap symbol? x)))
(define+provide (to-string x) (define+provide (to-string x)
(if (string? x) (if (string? x)
@ -42,7 +43,7 @@
#:symbol-proc (symbol? . -> . xexpr?) #:symbol-proc (symbol? . -> . xexpr?)
#:valid-char-proc (valid-char? . -> . xexpr?) #:valid-char-proc (valid-char? . -> . xexpr?)
#:cdata-proc (cdata? . -> . xexpr?) #:cdata-proc (cdata? . -> . xexpr?)
#:exclude-tags (listof symbol?) ) . ->* . txexpr?) #:exclude-tags symbols?) . ->* . txexpr?)
(let loop ([x txexpr]) (let loop ([x txexpr])
@ -88,7 +89,7 @@
#:symbol-proc (symbol? . -> . xexpr?) #:symbol-proc (symbol? . -> . xexpr?)
#:valid-char-proc (valid-char? . -> . xexpr?) #:valid-char-proc (valid-char? . -> . xexpr?)
#:cdata-proc (cdata? . -> . xexpr?) #:cdata-proc (cdata? . -> . xexpr?)
#:exclude-tags (listof symbol?) ) . ->* . txexpr-elements?) #:exclude-tags symbols?) . ->* . txexpr-elements?)
(define temp-tag (gensym "temp-tag")) (define temp-tag (gensym "temp-tag"))
(define decode-result (decode `(temp-tag ,@elements) (define decode-result (decode `(temp-tag ,@elements)

@ -28,9 +28,11 @@
(coerce/path? . -> . coerce/boolean?) (coerce/path? . -> . coerce/boolean?)
(not ((->string path) . starts-with? . "."))) (not ((->string path) . starts-with? . ".")))
(define (paths? x) (and (list? x) (andmap path? x)))
(define (complete-paths? x) (and (list? x) (andmap complete-path? x)))
(define+provide/contract (visible-files dir) (define+provide/contract (visible-files dir)
(pathish? . -> . (listof path?)) (pathish? . -> . paths?)
(filter visible? (filter visible?
(map (λ(p) (find-relative-path dir p)) (map (λ(p) (find-relative-path dir p))
(filter file-exists? (filter file-exists?
@ -108,7 +110,7 @@
(define+provide/contract (project-files-with-ext ext) (define+provide/contract (project-files-with-ext ext)
(coerce/symbol? . -> . (listof complete-path?)) (coerce/symbol? . -> . complete-paths?)
(map ->complete-path (filter (λ(i) (has-ext? i ext)) (directory-list (world:current-project-root))))) (map ->complete-path (filter (λ(i) (has-ext? i ext)) (directory-list (world:current-project-root)))))

@ -10,6 +10,9 @@
(->boolean (and (symbol? x) (with-handlers ([exn:fail? (λ(e) #f)]) (->boolean (and (symbol? x) (with-handlers ([exn:fail? (λ(e) #f)])
(not (whitespace/nbsp? (->string x))))))) (not (whitespace/nbsp? (->string x)))))))
(define+provide (pagenodes? x)
(and (list? x) (andmap pagenode? x)))
(define+provide (pagenodeish? x) (define+provide (pagenodeish? x)
(with-handlers ([exn:fail? (λ(e) #f)]) (with-handlers ([exn:fail? (λ(e) #f)])
@ -78,7 +81,7 @@
(define+provide/contract (children p [pt (current-pagetree)]) (define+provide/contract (children p [pt (current-pagetree)])
(((or/c #f pagenodeish?)) (pagetree?) . ->* . (or/c #f (listof pagenode?))) (((or/c #f pagenodeish?)) (pagetree?) . ->* . (or/c #f pagenodes?))
(and pt p (and pt p
(let ([pagenode (->pagenode p)]) (let ([pagenode (->pagenode p)])
(if (equal? pagenode (car pt)) (if (equal? pagenode (car pt))
@ -87,19 +90,18 @@
(define+provide/contract (siblings pnish [pt (current-pagetree)]) (define+provide/contract (siblings pnish [pt (current-pagetree)])
(((or/c #f pagenodeish?)) (pagetree?) . ->* . (or/c #f (listof pagenode?))) (((or/c #f pagenodeish?)) (pagetree?) . ->* . (or/c #f pagenodes?))
(children (parent pnish pt) pt)) (children (parent pnish pt) pt))
;; flatten tree to sequence ;; flatten tree to sequence
(define+provide/contract (pagetree->list pt) (define+provide/contract (pagetree->list pt)
(pagetree? . -> . (listof pagenode?)) (pagetree? . -> . pagenodes?)
; use cdr to get rid of root tag at front ; use cdr to get rid of root tag at front
(cdr (flatten pt))) (cdr (flatten pt)))
(define (adjacents side pnish [pt (current-pagetree)]) (define (adjacents side pnish [pt (current-pagetree)])
; ((symbol? (or/c #f pagenodeish?)) (pagetree?) . ->* . (or/c #f (listof pagenode?)))
(and pt pnish (and pt pnish
(let* ([pagenode (->pagenode pnish)] (let* ([pagenode (->pagenode pnish)]
[proc (if (equal? side 'left) takef takef-right)] [proc (if (equal? side 'left) takef takef-right)]
@ -108,12 +110,12 @@
(define+provide/contract (previous* pnish [pt (current-pagetree)]) (define+provide/contract (previous* pnish [pt (current-pagetree)])
(((or/c #f pagenodeish?)) (pagetree?) . ->* . (or/c #f (listof pagenode?))) (((or/c #f pagenodeish?)) (pagetree?) . ->* . (or/c #f pagenodes?))
(adjacents 'left pnish pt)) (adjacents 'left pnish pt))
(define+provide/contract (next* pnish [pt (current-pagetree)]) (define+provide/contract (next* pnish [pt (current-pagetree)])
(((or/c #f pagenodeish?)) (pagetree?) . ->* . (or/c #f (listof pagenode?))) (((or/c #f pagenodeish?)) (pagetree?) . ->* . (or/c #f pagenodes?))
(adjacents 'right pnish pt)) (adjacents 'right pnish pt))

@ -1,9 +1,10 @@
#lang racket/base #lang racket/base
(require "world.rkt" sugar/define sugar/coerce) (require "world.rkt" sugar/define sugar/coerce)
(define (paths? x) (and (list? x) (andmap path? x)))
(define/contract+provide (get-directory-require-files source-path) ; keep contract local to ensure coercion (define/contract+provide (get-directory-require-files source-path) ; keep contract local to ensure coercion
(coerce/path? . -> . (or/c #f (listof path?))) (coerce/path? . -> . (or/c #f paths?))
(define possible-requires (list (simplify-path (build-path source-path 'up world:directory-require)))) (define possible-requires (list (simplify-path (build-path source-path 'up world:directory-require))))
(and (andmap file-exists? possible-requires) possible-requires)) (and (andmap file-exists? possible-requires) possible-requires))

@ -16,8 +16,17 @@
;; using internal contracts to provide some extra safety (negligible performance hit) ;; using internal contracts to provide some extra safety (negligible performance hit)
(define/contract (valid-path-arg? x)
(any/c . -> . boolean?)
(or (equal? #f x) (complete-path? x)))
(define/contract (valid-path-args? x)
(any/c . -> . boolean?)
(and (list? x) (andmap valid-path-arg? x)))
(define/contract (make-mod-dates-key paths) (define/contract (make-mod-dates-key paths)
((listof (or/c #f complete-path?)) . -> . (listof (or/c #f complete-path?))) (valid-path-args? . -> . valid-path-args?)
paths) ; for now, this does nothing; maybe later, it will do more paths) ; for now, this does nothing; maybe later, it will do more
@ -27,20 +36,21 @@
(define/contract (store-render-in-modification-dates . rest-paths) (define/contract (store-render-in-modification-dates . rest-paths)
(() #:rest (listof (or/c #f complete-path?)) . ->* . void?) (() #:rest valid-path-args? . ->* . void?)
(define key (make-mod-dates-key rest-paths)) (define key (make-mod-dates-key rest-paths))
(hash-set! modification-date-hash key (map path->mod-date-value key))) (hash-set! modification-date-hash key (map path->mod-date-value key)))
(define/contract (modification-date-expired? . rest-paths) (define/contract (modification-date-expired? . rest-paths)
(() #:rest (listof (or/c #f complete-path?)) . ->* . boolean?) (() #:rest valid-path-args? . ->* . boolean?)
(define key (make-mod-dates-key rest-paths)) (define key (make-mod-dates-key rest-paths))
(or (not (key . in? . modification-date-hash)) ; no stored mod date (or (not (key . in? . modification-date-hash)) ; no stored mod date
(not (equal? (map path->mod-date-value key) (get modification-date-hash key))))) ; data has changed (not (equal? (map path->mod-date-value key) (get modification-date-hash key))))) ; data has changed
(define (list-of-pathish? x) (and (list? x) (andmap pathish? x)))
(define/contract+provide (render-batch . xs) (define/contract+provide (render-batch . xs)
(() #:rest (listof pathish?) . ->* . void?) (() #:rest list-of-pathish? . ->* . void?)
;; Why not just (map render ...)? ;; Why not just (map render ...)?
;; Because certain files will pass through multiple times (e.g., templates) ;; Because certain files will pass through multiple times (e.g., templates)
;; And with render, they would be rendered repeatedly. ;; And with render, they would be rendered repeatedly.

@ -2,7 +2,7 @@
(require txexpr sugar/define) (require txexpr sugar/define)
(define/contract+provide (make-default-tag-function . ids) (define/contract+provide (make-default-tag-function . ids)
(() #:rest (listof txexpr-tag?) . ->* . procedure?) (() #:rest txexpr-tags? . ->* . procedure?)
(define (make-one-tag id) (define (make-one-tag id)
(λ x (λ x
(define reversed-pieces ; list of attribute pairs, and last element holds a list of everything else, then reversed (define reversed-pieces ; list of attribute pairs, and last element holds a list of everything else, then reversed

@ -24,7 +24,7 @@
(define+provide/contract (select* key value-source) (define+provide/contract (select* key value-source)
(coerce/symbol? (or/c hash? txexpr? pagenode? pathish?) . -> . (or/c #f (listof txexpr-element?))) (coerce/symbol? (or/c hash? txexpr? pagenode? pathish?) . -> . (or/c #f txexpr-elements?))
(define metas-result (and (not (txexpr? value-source)) (select-from-metas key value-source))) (define metas-result (and (not (txexpr? value-source)) (select-from-metas key value-source)))
(define doc-result (select-from-doc key value-source)) (define doc-result (select-from-doc key value-source))
(define result (append (or (and metas-result (list metas-result)) null) (or doc-result null))) (define result (append (or (and metas-result (list metas-result)) null) (or doc-result null)))
@ -40,7 +40,7 @@
(define+provide/contract (select-from-doc key doc-source) (define+provide/contract (select-from-doc key doc-source)
(coerce/symbol? (or/c txexpr? pagenode? pathish?) . -> . (or/c #f (listof txexpr-element?))) (coerce/symbol? (or/c txexpr? pagenode? pathish?) . -> . (or/c #f txexpr-elements?))
(define doc (cond (define doc (cond
[(txexpr? doc-source) doc-source] [(txexpr? doc-source) doc-source]
[else (get-doc doc-source)])) [else (get-doc doc-source)]))

Loading…
Cancel
Save