PasteRack.org
Paste # 17902
2019-03-13 17:20:55

Forked from paste # 17805.

Fork as a new paste.

Paste viewed 417 times.


Embed:

  1. #lang racket
  2.  
  3. (define-syntax (print1 stx) (printf "1\n") #'(void))
  4. (define-syntax (print2 stx) (printf "2\n") #'(void))
  5.  
  6. (define-syntax (eager-block stx)
  7.   (syntax-case stx ()
  8.     [(_ args ...) #`(begin
  9.                       #,@(map (λ (arg) (local-expand arg 'expression #f))
  10.                               (syntax->list #'(args ...))))]))
  11.  
  12. (eager-block (print1) (print2)) ;; prints 1 2 at compile-time
  13. (eager-block (print1) (eager-block (print2))) ;; prints 1 2 at compile-time
  14. ;; prints 2 1 at compile-time inside a module, but 1 2 at the REPL (and on PasteRack)
  15. (begin (let () (print1)) (eager-block (print2)))
  16.  

=>

1

2

1

2

1

2