From fbed39423f61ed2a5262e8c07c897f66e4f1ce9e Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Thu, 6 Feb 2014 21:59:24 -0800 Subject: [PATCH] add bound/c to guarantee function is defined --- main-helper.rkt | 13 ++++++++++++- main.rkt | 19 +++---------------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/main-helper.rkt b/main-helper.rkt index 6b69122..d0f44e4 100644 --- a/main-helper.rkt +++ b/main-helper.rkt @@ -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))) diff --git a/main.rkt b/main.rkt index 56d74de..fc041cd 100644 --- a/main.rkt +++ b/main.rkt @@ -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,