PasteRack.org
Paste # 14109
2020-02-15 10:53:58

Fork as a new paste.

Paste viewed 296 times.


Embed:

  1. #lang racket/base
  2.  
  3. (define (make-true-when-called-N-times n)
  4.   (define counter 1)
  5.   (define (predicate?)
  6.     (begin0 (= counter n)
  7.       (set! counter (add1 counter))))
  8.   predicate?)
  9.  
  10. (define true-when-called-2-times (make-true-when-called-N-times 2))
  11. (true-when-called-2-times)
  12. (true-when-called-2-times)
  13. (true-when-called-2-times)
  14. (true-when-called-2-times)

=>

#f

#t

#f

#f