Oh wow, that's impressively better than what I wrote! I didn't know one could have *recursive* macros, to say nothing about the proper usage of syntax-parse.
Thank you very much for your quick answer! - Sergiu On Wednesday, December 16, 2020 at 11:03:49 PM UTC+1 [email protected] wrote: > syntax-parse can already perform pattern matching. No need to use match > > (define-syntax (multi-compose stx) > (syntax-parse stx > [(_ f:expr g:expr) > #'(compose f g)] > [(_ f:expr funcs:expr ...) > #'(compose f (multi-compose funcs ...))])) > > > On Wed, Dec 16, 2020 at 1:37 PM unlimitedscolobb <[email protected]> > wrote: > >> On Thursday, December 10, 2020 at 6:01:52 PM UTC+1 unlimitedscolobb wrote: >> >>> On Thursday, December 10, 2020 at 5:49:43 PM UTC+1 [email protected] >>> wrote: >>> >>> A macro might be able to generate either of the above from >>>> (comp f g h k) >>>> . >>>> >>> Indeed. I'm re-reading the docs on macros and I think I see a clean and >>> clear way to achieve what I need. >>> >>> I'll post my attempt as soon as I get the time to write it. >>> >>> >> Okay, so this is my shot: >> >> #lang typed/racket >> >> (require (for-syntax syntax/parse racket/match)) >> >> (define-syntax (multi-compose stx) >> (syntax-parse stx >> [(_ funcs:expr ...) >> (match-define (list fn fn-1 fs ...) >> (reverse (syntax->list #'(funcs ...)))) >> (datum->syntax stx (for/fold ([sexp `(compose ,fn-1 ,fn)]) >> ([f (in-list fs)]) >> `(compose ,f ,sexp)))])) >> >> (multi-compose f1 f2 ... fn-1 fn) expands to (compose f1 (compose f2 ( >> ... (compose fn-1 fn) ... ))) >> >> My syntax-transformation-fu is essentially non-existent, even after >> reading through Greg's Fear of Macros multiple times, so please do tell me >> if you see some flagrant opportunities for improvement in the code above. >> >> I'm planning to throw together a small package with compose-n , compose-3 >> to compose-10, and multi-compose, and publish it. It would normally be my >> Christmas package for myself, but it make take some more time :-) >> >> - >> Sergiu >> >> -- >> > You received this message because you are subscribed to the Google Groups >> "Racket Users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> > To view this discussion on the web visit >> https://groups.google.com/d/msgid/racket-users/219c189f-dd93-4b18-9ef9-2ff477ce3a15n%40googlegroups.com >> >> <https://groups.google.com/d/msgid/racket-users/219c189f-dd93-4b18-9ef9-2ff477ce3a15n%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/f067ec8c-ed47-4718-944b-eb3a40e53234n%40googlegroups.com.

