PasteRack.org
Paste # 85722
2018-04-16 18:01:25

Forked from paste # 90182.

Fork as a new paste.

Paste viewed 729 times.


Embed:

mailing list question

  1. #lang racket
  2. (require (for-syntax syntax/parse racket/list))
  3.  
  4. (begin-for-syntax
  5.   (struct communicate (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 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 ([x e] ...)
  18.          (let-syntax ([x (communicate
  19.                            (length (flatten (syntax->datum #'e))))] ...)
  20.            body))]))
  21. (my-let ([x '(a . (b . (((c . d) . 4) . 5)))])
  22.   (access x))

=>

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

  in: x