Last active
December 28, 2015 03:59
-
-
Save Metaxal/7439440 to your computer and use it in GitHub Desktop.
condd4: The Design Space of Conditionals with Embedded Defines
This file contains 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 | |
(require (for-syntax racket/base | |
syntax/parse) | |
racket/list | |
racket/match) | |
;; Related post: http://jeapostrophe.github.io/2013-11-12-condd-post.html | |
(define (f-condd4 l) | |
(condd4 | |
[(empty? l) empty] | |
#:def (match-define (cons fst rst) l) | |
[(zero? (modulo fst 3)) | |
(cons 3 (f-condd4 rst))] | |
[(zero? (modulo fst 4)) | |
(cons (+ fst 4) rst)] | |
[else | |
(list fst)])) | |
(define-syntax (condd4 stx) | |
(syntax-parse stx | |
#:literals (else) | |
[(_) | |
#'(error 'condd4 "Fell through without else clause")] | |
[(_ [else . d]) | |
#'(let () . d)] | |
[(_ #:def def . tail) | |
#'(let () | |
def | |
(condd4 . tail))] | |
[(_ [test . b] . more) | |
#'(if test | |
(let () . b) | |
(condd4 . more))])) | |
(f-condd4 (range 10)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment