www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

try-attribute.rkt (496B)


      1 #lang racket/base
      2 
      3 (require (for-syntax racket/base))
      4 
      5 (provide try-attribute if-attribute)
      6 
      7 (define-syntax (if-attribute stx)
      8   (syntax-case stx ()
      9     [(_ name if-branch else-branch)
     10      (if (syntax-pattern-variable? (syntax-local-value #'name (λ () #f)))
     11          #'if-branch
     12          #'else-branch)]))
     13 
     14 (define-syntax (try-attribute stx)
     15   (syntax-case stx ()
     16     [(_ name fallback)
     17      #'(if-attribute (attribute name) fallback)]
     18     [(_ name)
     19      #'(if-attribute (attribute name) #f)]))