Created
September 21, 2021 13:00
-
-
Save Metaxal/e85c19acd3de0069fbe4f84b01491049 to your computer and use it in GitHub Desktop.
Hygienic 'threading' macro for Racket
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket/base | |
(require (for-syntax racket/base | |
syntax/parse)) | |
(provide with) | |
(define-syntax (with stx) | |
(syntax-parse stx | |
[(with it last) | |
#'last] | |
[(with it body1 body2 ...) | |
#'(let ([it body1]) | |
(with it body2 ...))])) | |
;;; Example | |
(module+ drracket | |
(require racket) | |
(with it | |
"Hey\nThis is a nice little doggy you have here\nCome here doggy!\nNice doggy indeed\nSee ya!" | |
(string-split it "\n") | |
(filter (λ (line) (string-contains? line "doggy")) it) | |
(sort it string<?) | |
(remove-duplicates it))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment