From 7b7e7776f2c64403cde8643a86b9f84f4b8ab244 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Fri, 14 Feb 2014 17:24:26 -0800 Subject: [PATCH] scribble sugar --- scribble.rkt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 scribble.rkt diff --git a/scribble.rkt b/scribble.rkt new file mode 100644 index 0000000..b8806f2 --- /dev/null +++ b/scribble.rkt @@ -0,0 +1,16 @@ +#lang racket +(require (for-syntax racket/base)) +(require "coerce.rkt") + + +(provide when/block) + +;; improves the syntax for conditional blocks in templates +;; ordinarily it would be @when[condition]{@list{stuff ...}} +;; now it can be @when/block[condition]{stuff ...} +;; has to be a macro otherwise body expressions will be evaluated regardless of condition +;; this is bad: if condition is false, expression should exit +(define-syntax (when/block stx) + (syntax-case stx () + [(_ condition body ...) + #'(if condition (string-append* (map ->string (list body ...))) "")]))