(module binding mzscheme (require "require.ss") (require-lists) (provide sexp->binding binding->sexp binding-lift (struct binding (key value))) ;; A (Binding Key Value) is (make-binding Key Value) (define-struct binding (key value)) ;; binding->sexp : (Binding Key Value) -> (list Key Value) ;; Builds a list from a binding. (define (binding->sexp binding) (list (binding-key binding) (binding-value binding))) ;; sexp->binding : (list Key Value) -> (Binding Key Value) ;; Builds a binding from a list. (define (sexp->binding sexp) (make-binding (first sexp) (second sexp))) ;; binding-lift : (Key ... -> T) -> ((Binding Key Any) ... -> T) ;; Consumes a function operating on keys. ;; Produces a function operating on bindings. (define (binding-lift key-fn) (lambda bindings (apply key-fn (map binding-key bindings)))) )