PasteRack.org
Paste # 88912
2018-10-07 12:43:09

Fork as a new paste.

Paste viewed 3590 times.


Embed:

#lang racket
(require (for-syntax syntax/parse))

(define-syntax (delayed-set! stx)
  (syntax-parse stx
    [(_delayed-set! id expr)
     (syntax/loc stx
       (let ([value expr])
         (sleep (random))
         (set! id value)))]))

(define x 10)

(thread (λ () (let loop ()
                (displayln (~a "1 before: " x))
                (delayed-set! x (+ x 1))
                (displayln (~a "1 after: " x))
                (loop))))

(thread (λ () (let loop ()
                (displayln (~a "2 before: " x))
                (delayed-set! x (+ x 1))
                (displayln (~a "2 after: " x))
                (loop))))