PasteRack.org
Paste # 4964
2018-06-20 02:25:06

Fork as a new paste.

Paste viewed 347 times.


Embed:

Struggling with macros

  1. #lang racket
  2.  
  3. (struct session (name) #:transparent)
  4.  
  5. (define current-session (make-parameter null))
  6.  
  7. (define (create-session)
  8.   (session "new session"))
  9.  
  10. (define-syntax (with-session stx)
  11.   (define ops (cdr (syntax->list stx)))
  12.   (datum->syntax stx
  13.                  `(parameterize ([current-session (create-session)]) ,ops)))
  14.  
  15.  
  16. (with-session (displayln (current-session)))

=>

#(struct:session new session)

application: not a procedure;

 expected a procedure that can be applied to arguments

  given: #<void>

  arguments...: [none]