PasteRack.org
Paste # 39331
2018-04-16 18:05:51

Forked from paste # 43101.

Fork as a new paste.

Paste viewed 739 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 (transformer value)
  6.     #:property prop:procedure (struct-field-index transformer)))
  7.  
  8. (define-syntax (access stx)
  9.   (syntax-parse stx
  10.     [(_ x:id)
  11.      #:fail-unless (communicate? (syntax-local-value #'x))
  12.      (format "Expected ~a to be bound by my-let" (syntax-e #'x))
  13.      #'(cons x '#,(communicate-value (syntax-local-value #'x)))]))
  14.  
  15. (define-syntax (my-let stx)
  16.   (syntax-parse stx
  17.     [(_ ([x:id e:expr] ...) body:expr)
  18.      #'(let-syntax ([x (communicate
  19.                          (make-variable-like-transformer #'e)
  20.                            (length (flatten (syntax->datum #'e))))] ...)
  21.            body)]))
  22. (my-let ([x '(a . (b . (((c . d) . 4) . 5)))])
  23.   (access x))

=>

eval:2:0: x: illegal use of syntax

  in: x