From 7b422d9a389f06b010805fa6f3abc3518ac0fa48 Mon Sep 17 00:00:00 2001 From: AlexKnauth Date: Sat, 18 Jun 2016 10:12:26 -0400 Subject: [PATCH] add postfix-in require form --- tapl/postfix-in.rkt | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tapl/postfix-in.rkt diff --git a/tapl/postfix-in.rkt b/tapl/postfix-in.rkt new file mode 100644 index 0000000..01f3e4e --- /dev/null +++ b/tapl/postfix-in.rkt @@ -0,0 +1,36 @@ +#lang racket/base + +(provide postfix-in) + +(require racket/require-syntax + racket/require + (for-syntax racket/base + syntax/parse + )) +(module+ test + (require rackunit)) + +(begin-for-syntax + ;; add-postfix : (-> String (-> String String)) + (define ((add-postfix postfix) str) + (string-append str postfix))) + +(define-require-syntax postfix-in + (lambda (stx) + (syntax-parse stx + [(postfix-in post-id:id require-spec) + #:with post-str:str (symbol->string (syntax-e #'post-id)) + #'(filtered-in (add-postfix 'post-str) require-spec)]))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(module+ test + (require (postfix-in - racket/base)) + + (define-binary-check (check-free-id=? actual expected) + (free-identifier=? actual expected)) + + (check-free-id=? #'#%app- #'#%app) + (check-free-id=? #'λ- #'λ) + (check-free-id=? #'define- #'define) + )