PasteRack.org
Paste # 69020
2022-12-06 23:43:29

Fork as a new paste.

Paste viewed 1426 times.


Embed:

  1. #lang racket
  2.  
  3. (require
  4.   racket/match
  5.   (for-syntax
  6.    racket/base
  7.    syntax/parse
  8.    ))
  9.  
  10. (begin-for-syntax
  11.     (define-syntax-class operation
  12.     #:attributes (op type)
  13.     #:literals (* /)
  14.     (pattern *
  15.              #:attr op #''multiply
  16.              #:attr type #'prod)
  17.     (pattern /
  18.              #:attr op #''divide
  19.              #:attr type #'div)
  20.     )
  21.   )
  22.  
  23. (define-syntax (expression stx)
  24.  
  25.   (syntax-parse stx
  26.     ([_ (op:operation)]
  27.      #:when (begin
  28.               (printf "~a ~a~n"
  29.                       (syntax->datum #'op.type)
  30.                       (eq? (syntax->datum #'op.type) 'div))
  31.               (eq? (syntax->datum #'op.type) 'div)
  32.               )
  33.      #'(list op.op 'op.type)
  34.      )
  35.     ))
  36.  
  37. (expression (/))

=>

div #t

'(divide div)