Last active
October 14, 2019 17:11
-
-
Save monkey413/1960d47ea6e20cda4ab76d5d777408cd to your computer and use it in GitHub Desktop.
fear_of_macros.rkt
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 | |
(define-syntax foo | |
(lambda (stx) | |
(syntax "I am foo"))) | |
(define-syntax (also-foo stx) | |
(syntax "I am also foo")) | |
(define-syntax (quoted-foo stx) | |
#'"I am also foo, using #' instead of syntax") | |
(define-syntax (say-hi stx) | |
#'(displayln "hi")) | |
(define-syntax (show-me stx) | |
(print stx) | |
#'(void)) | |
(define stx #'(if x (list "true") #f)) | |
(syntax-source stx) | |
(syntax-line stx) | |
(syntax->datum stx) | |
(syntax-e stx) ;; one level down | |
(syntax->list stx) | |
(define-syntax (reverse-me stx) | |
(datum->syntax stx (reverse (cdr (syntax->datum stx))))) | |
(require (for-syntax racket/match)) | |
(define-syntax (our-if-using-match-v2 stx) | |
(match (syntax->list stx) | |
[(list _ condition true-expr false-expr) | |
(datum->syntax stx `(cond [,condition ,true-expr] | |
[else ,false-expr]))])) | |
(define-syntax (our-if-using-syntax-case stx) | |
(syntax-case stx () | |
[(_ condition true-expr false-expr) | |
#'(cond [condition true-expr] | |
[else false-expr])])) | |
(define-syntax-rule (our-if-using-syntax-rule condition true-expr false-expr) | |
(cond [condition true-expr] | |
[else false-expr])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment