From 03dc7eb0e5b756cc5c7e2cc9db435e0c5b93b1fd Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Fri, 18 Dec 2020 12:58:43 +0100 Subject: [PATCH] Add multi-compose. --- typed-compose.rkt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/typed-compose.rkt b/typed-compose.rkt index 75f86e1..b122373 100644 --- a/typed-compose.rkt +++ b/typed-compose.rkt @@ -121,3 +121,19 @@ ((compose-8 n->s add1 add1 add1 add1 add1 add1 s->n) "3") "9") (check-equal? ((compose-9 n->s add1 add1 add1 add1 add1 add1 add1 s->n) "3") "10")) + +(define-syntax (multi-compose stx) + ;; Implementation by Sorawee Porncharoenwase. + (syntax-parse stx + [(_ f:expr g:expr) + #'(compose f g)] + [(_ f:expr funcs:expr ...) + #'(compose f (multi-compose funcs ...))])) + +(module+ test + (check-equal? ((multi-compose add1 + (λ ([x : Number]) (* x 3)) + add1 + (λ ([x : Number]) (+ x 2))) + 3) + 19))