PasteRack.org
Paste # 19038
2019-10-12 10:50:39

Fork as a new paste.

Paste viewed 116 times.


Embed:

struct macro failure

  1. #lang racket
  2.  
  3. (require (for-syntax syntax/parse))
  4.  
  5. (begin-for-syntax
  6.   (define-struct object (colour size))
  7.   (define ball (object 'red 'small))
  8.  
  9.   (define-syntax-class struct
  10.     [pattern s #:fail-unless (struct? (syntax-e #'s))
  11.              "Expected struct?"]))
  12.  
  13. (define-syntax (touch-struct stx)
  14.   (syntax-parse stx
  15.     [(_ obj:struct)
  16.      #`#,(object-colour #'obj)]))
  17.  
  18. (define-syntax (run stx)
  19.   (syntax-parse stx
  20.     [(_)
  21.      #'(touch-struct ball)]))
  22.  
  23. #;(run)

=>