Created
March 27, 2018 23:17
-
-
Save jboynyc/a3762d56dbef41bb250a19609cb145bd to your computer and use it in GitHub Desktop.
racket macro experimentation
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 define-html-tag | |
(syntax-rules () | |
[(_ element) | |
(define element | |
(let ([es (symbol->string 'element)]) | |
(make-keyword-procedure | |
(lambda [keys vals . contents] | |
(let ([properties (string-join | |
(for/list ([k keys] | |
[v vals]) | |
(format "~a=\"~a\"" (keyword->string k) v)))] | |
[text (string-join contents " ")]) | |
(format "<~a ~a>~a</~a>" es properties text es))) | |
(lambda [contents . rest] | |
(if (empty? rest) | |
(format "<~a>~a</~a>" es contents es) | |
(format "<~a>~a ~a</~a>" es contents (string-join rest) es))))))])) | |
(define-html-tag a) | |
(define-html-tag p) | |
(define-html-tag strong) | |
(define-html-tag div) | |
(printf | |
(div #:class "float-left" | |
(div #:id "statement" | |
(p "hi" (strong "my friends") "let's go" (a #:href "http://joinmastodon.org" "join mastodon!"))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment