#lang racket/base ;; ;;; Copyright 2010, 2011, 2012, 2013 Tony Garnock-Jones ;;; ;;; This file is part of marketplace-ssh. ;;; ;;; marketplace-ssh is free software: you can redistribute it and/or ;;; modify it under the terms of the GNU General Public License as ;;; published by the Free Software Foundation, either version 3 of the ;;; License, or (at your option) any later version. ;;; ;;; marketplace-ssh is distributed in the hope that it will be useful, ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;;; General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with marketplace-ssh. If not, see ;;; . (provide define-mapping) (define-syntax check-defaults (syntax-rules () ((_ fn bn fd bd #:forward-default new-fd rest ...) (check-defaults fn bn new-fd bd rest ...)) ((_ fn bn fd bd #:backward-default new-bd rest ...) (check-defaults fn bn fd new-bd rest ...)) ((_ fn bn fd bd (lhs rhs) ...) (begin (define (fn l) (case l ((lhs) 'rhs) ... (else (fd l)))) (define (bn r) (case r ((rhs) 'lhs) ... (else (bd r)))))))) (define (die-with-mapping-name n) (lambda (v) (raise (exn:fail:contract (format "~v: Mapping not found for ~v" n v) (current-continuation-marks))))) (define-syntax define-mapping (syntax-rules () ((_ forward-name backward-name rest ...) (check-defaults forward-name backward-name (die-with-mapping-name 'forward-name) (die-with-mapping-name 'backward-name) rest ...))))