(module ns-state-stx mzscheme (require (lib "match.ss") "ns-utils.ss" ;; lookup not-found "rpn.ss" ;; rpn-compiler-stx "rpn-runtime.ss") ;; state-lift (require-for-syntax "rpn-tx.ss") ;; state-represent/find (provide ns-state-stx) ;; See base-stx.ss for more info. ;; The state syntax uses two lists of namespaces. The first one ;; contains state words, the second one normal functions that will ;; be automatically lifted. This function creates an 'find' method ;; to be plugged into 'state-represent' syntax defined in rpn-tx.ss ;; That transformer passes in an extra argument to find which ;; indicates what kind of function to return. ;; For state words, look for a genuine state word, or lift one from ;; the base dictionaries. For base words just return an unlifted ;; function. If symbol lookup fails, the parameterized function ;; 'not-found' is called with the appropriate failed paths. (define (make-state-find state base) (match-lambda* ((name 'state) (or (lookup state name) (state-lift (lookup base name)) (not-found name state base))) ((name 'base) (or (lookup base name) (not-found name base))))) ;; Using the function above, the 'state-stx' macro can be created ;; from 'state-rpn' defined in rpn-tx. Use the resulting macro as: ;; (state-stx lang: ((internal) ...) ((external) ...)) (rpn-compiler-stx ns-state-stx ns-state-rpn make-state-find) ;; For documentation see rpn.ss )