From a83f1b9978a2a2e4e246221a312bf767611d1d8b Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Mon, 21 Dec 2020 22:00:29 +0100 Subject: [PATCH] utils.rkt: Replace compose-related definitions with requiring typed-compose. --- utils.rkt | 41 ++++------------------------------------- 1 file changed, 4 insertions(+), 37 deletions(-) diff --git a/utils.rkt b/utils.rkt index 613ddea..cf5c3e8 100644 --- a/utils.rkt +++ b/utils.rkt @@ -1,13 +1,14 @@ #lang typed/racket -(require (for-syntax syntax/parse racket/list)) +(require (for-syntax syntax/parse racket/list) + typed-compose) (provide Variable VariableMapping GeneralPair eval-with eval1-with extract-symbols any->string stringify-variable-mapping string->any map-sexp - read-org-sexp unorg unstringify-pairs compose-n compose-3 compose-4 - multi-compose read-org-variable-mapping unorgv + read-org-sexp unorg unstringify-pairs + read-org-variable-mapping unorgv ;; Syntax auto-hash-ref/explicit auto-hash-ref/:) @@ -129,40 +130,6 @@ '(x y z)))) -;;; ========================= -;;; Composing typed functions -;;; ========================= - -(: compose-n (All (a) (-> (-> a a) * (-> a a)))) -(define (compose-n . funcs) - (λ (x) - (for/foldr ([x x]) ([f funcs]) - (f x)))) - -(: compose-3 (All (a b c d) (-> (-> c d) (-> b c) (-> a b) (-> a d)))) -(define (compose-3 f1 f2 f3) - (λ (x) (f1 (f2 (f3 x))))) -(: compose-4 (All (a b c d e) (-> (-> d e) (-> c d) (-> b c) (-> a b) (-> a e)))) -(define (compose-4 f1 f2 f3 f4) - (λ (x) (f1 (f2 (f3 (f4 x)))))) - -(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)) - - ;;; ========================= ;;; Org-mode interoperability ;;; =========================