PasteRack.org
Paste # 30244
2018-04-16 18:07:11

Forked from paste # 39331.

Fork as a new paste.

Paste viewed 746 times.


Embed:

mailing list question

  1. #lang racket
  2. (require (for-syntax syntax/parse racket/list syntax/transformer))
  3.  
  4. (begin-for-syntax
  5.   (struct communicate (syntax value) #:prefab))
  6.  
  7. (define-syntax (access stx)
  8.   (syntax-parse stx
  9.     [(_ x:id)
  10.      #:fail-unless (communicate? (syntax-local-value #'x))
  11.      (format "Expected ~a to be bound by my-let" (syntax-e #'x))
  12.      #'(cons #,(communicate-syntax x) '#,(communicate-value (syntax-local-value #'x)))]))
  13.  
  14. (define-syntax (my-let stx)
  15.   (syntax-parse stx
  16.     [(_ ([x:id e:expr] ...) body:expr)
  17.      #'(let-syntax ([x (communicate #'e
  18.                            (length (flatten (syntax->datum #'e))))] ...)
  19.            body)]))
  20. (my-let ([x '(a . (b . (((c . d) . 4) . 5)))])
  21.   (access x))

=>

program::-1: unsyntax: illegal outside of quasisyntax

  in: (unsyntax (communicate-syntax x))