I'm trying to implement the macros -> and ->> in Scheme and my final result was:
;;
;; See https://clojuredocs.org/clojure.core/-%3E
;; for more info.
;;
(define-syntax ->
(syntax-rules ()
((_ a) a)
((_ a (b c ...)) (b a c ...))
((_ a b) (b a))
((_ a b c) (-> (-> a b) c))
((_ a b ... c) (-> (-> a b ...) c))))
;;
;; See https://clojuredocs.org/clojure.core/-%3E%3E
;; for more info.
;;
(define-syntax ->>
(syntax-rules ()
((_ a) a)
((_ a (b c ...)) (b c ... a))
((_ a b) (b a))
((_ a b c) (->> (->> a b) c))
((_ a b ... c) (->> (->> a b ...) c))))
I have made some tests successfully, but I am not sure if it is 100% correct and if it is 100% optimized.
Is it correct? Is there any way to optimize this? Did I do too much or is it anyway?