PasteRack.org
Paste # 56189
2020-02-16 07:23:59

Fork as a new paste.

Paste viewed 228 times.


Embed:

  1. #lang racket
  2.  
  3. (begin-for-syntax (struct syntax-info (position module) #:transparent))
  4. (define logged-syntax (list))
  5.  
  6. (define-syntax (log-var stx)
  7.   (syntax-case stx ()
  8.     [(_ id)
  9.      #'(printf "The value of '~a' is: ~a\n" (syntax->datum #'id) id)]))
  10.  
  11. (define-syntax log-once
  12.   (syntax-rules ()
  13.     [(log-once id next ...)
  14.      (with-syntax ([id-stx (syntax-info (syntax-position #'id) (syntax-source-module #'id))])
  15.        (unless (member id-stx logged-syntax)
  16.            (set! logged-syntax (cons id-stx logged-syntax))
  17.            (log-var id)
  18.            (log-once next ...)))]))

=>