utils.rkt: Replace multi-compose by the implementation by Sorawee.

This commit is contained in:
Sergiu Ivanov 2020-12-16 23:21:33 +01:00
parent b73a5ce91e
commit 3ed8f24277

View file

@ -1,7 +1,6 @@
#lang typed/racket
(require (for-syntax syntax/parse racket/list
(only-in racket/match match-define)))
(require (for-syntax syntax/parse racket/list))
(provide Variable VariableMapping GeneralPair
eval-with eval1-with
@ -148,13 +147,12 @@
(λ (x) (f1 (f2 (f3 (f4 x))))))
(define-syntax (multi-compose stx)
;; Implementation by Sorawee Porncharoenwase.
(syntax-parse stx
[(_ f1 f2 funcs ...)
(match-define (list fn fn-1 fs ...)
(reverse (cons #'f1 (cons #'f2 (syntax->list #'(funcs ...))))))
(datum->syntax stx (for/fold ([sexp `(compose ,fn-1 ,fn)])
([f (in-list fs)])
`(compose ,f ,sexp)))]))
[(_ f:expr g:expr)
#'(compose f g)]
[(_ f:expr funcs:expr ...)
#'(compose f (multi-compose funcs ...))]))
(module+ test
(check-equal? ((multi-compose add1