Last active
April 20, 2021 14:35
-
-
Save shhyou/ab9a3d48a5e12e10d8fa440af94adfab to your computer and use it in GitHub Desktop.
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 | |
racket/syntax | |
syntax/parse)) | |
(define-syntax (define-constant stx) | |
(syntax-parse stx | |
[(_ name:id | |
(~optional (~and #:evaluate evaluate-kw)) | |
value:expr) | |
#:with value-maybe-eval (if (attribute evaluate-kw) | |
#',value | |
#'value) | |
(syntax/loc stx | |
(begin | |
(begin-for-syntax | |
(define/with-syntax name #'value-maybe-eval)) | |
(define name value)))])) | |
(define-syntax (quasiquote/constants stx) | |
(syntax-parse stx | |
[(_ datum:expr) | |
(quasisyntax/loc stx | |
(let-syntax ([datum-with-constants (λ (unused-stx) #'`datum)]) | |
datum-with-constants))])) | |
(define-constant CONST (+ 3 5)) | |
(define-constant CONST2 #:evaluate | |
(* 5 CONST)) | |
(list CONST 234 CONST2) | |
(quasiquote/constants | |
(list CONST 234 CONST2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment