add bound/c to guarantee function is defined

pull/9/head
Matthew Butterick 11 years ago
parent ebfe5aa8e3
commit fbed39423f

@ -4,10 +4,21 @@
(require (for-syntax racket/rerequire pollen/tools pollen/world))
(require pollen/tools pollen/world)
(provide (all-defined-out))
(provide here-path get-here-path require-extras require-and-provide-extras bound/c
(rename-out (top~ #%top)))
(module+ test (require rackunit))
(define-syntax-rule (top~ . id)
(λ x `(id ,@x)))
(define-syntax (bound/c stx)
(syntax-case stx ()
[(_ x)
(if (identifier-binding #'x )
#'x
#'(#%top . x))]))
(define-for-syntax (put-file-in-require-form file)
`(file ,(->string file)))

@ -25,19 +25,6 @@
(require pollen/tools pollen/main-helper)
(require-and-provide-extras) ; brings in the project require files
;; #%top binding catches ids that aren't defined
;; here, convert them to basic xexpr
;; #%top is a syntax transformer that returns a function
;; λ x captures all the args (vs. λ(x), which only catches one)
;; and id is not spliced because it's syntax, not a true variable
;; WARNING! This is convenient for writing pollen documents
;; (which is why it works this way)
;; but it makes debugging tricky, because an undefined (symbol item ...)
;; is just treated as a valid tagged-xexpr, not an undefined function.
(define-syntax-rule (#%top . id)
;; todo: can #%top emit a debug message when a function hits it?
(λ x `(id ,@x)))
expr ... ; body of module
;; set up a hook for identifier 'here'
@ -47,9 +34,9 @@
(provide (all-from-out ; pollen file should bring its requires
pollen/tools)))
(require 'pollen-inner) ; provides doc & #%top, among other things
(require 'pollen-inner) ; provides doc, among other things
(define here (path->pnode inner-here-path))
(define here ((bound/c path->pnode) inner-here-path))
;; prepare the elements, and append inner-here-path as meta.
;; put it first so it can be overridden by custom meta later on
@ -85,7 +72,7 @@
(define main (apply (if here-is-ptree?
;; ptree source files will go this way,
ptree-source-decode
(bound/c ptree-source-decode)
;; ... but other files, including pollen, will go this way.
;; Root is treated as a function.
;; If it's not defined elsewhere,

Loading…
Cancel
Save