|
34 | 34 | ; (while (and (<= 50 (milliseconds)) (<= (milliseconds) 100)) ...
|
35 | 35 | ; or this:
|
36 | 36 | ; (while (and (<= 50 (milliseconds)) (>= 100 (milliseconds))) ...
|
37 |
| - ; plus the analogous versions for the lower bound test, so 4 possible combinations in all. (Is there a better way to do this??) |
| 37 | + ; plus the analogous versions for the lower bound test, so 4 possible combinations in all. |
| 38 | + ; NOTE: this should be rewritten in better style -- see e.g. the integral macro, which uses syntax-parse |
38 | 39 | ((while (and (<= lower (milliseconds)) (<= (milliseconds) upper)) e ...)
|
39 | 40 | (add-while-with-time-bounds lower upper e ...))
|
40 | 41 | ((while (and (<= lower (milliseconds)) (>= upper (milliseconds))) e ...)
|
|
90 | 91 | (with-syntax ([id (datum->syntax stx (gensym))])
|
91 | 92 | #'(send this max-min-helper fn (lambda () (send this wally-evaluate expr)) 'id (interesting-time?)))]))
|
92 | 93 | ; integral macro
|
| 94 | +; The form is (integral expr) with additional optional keyword arguments as follows: |
| 95 | +; #:var v -- variable of integration; default is (milliseconds) -- note that an expression is allowed here |
| 96 | +; #:numeric or #:symbolic -- which kind of integration to use. Default is to try symbolic, and if that doesn't work, use numeric |
| 97 | +; #:dt d -- time step (only allowed with #:numeric) |
| 98 | +; Example: (integral (sin x) #:var x #:numeric #:dt 0.1) |
93 | 99 | (require (for-syntax "symbolic-integration.rkt")) ; function to do simple symbolic integration
|
| 100 | +(require (for-syntax syntax/parse)) |
94 | 101 | (define-syntax (integral stx)
|
95 |
| - (syntax-case stx () |
96 |
| - [(_ expr var) ; case with explicit variable of integration |
97 |
| - (with-syntax ([intgl (datum->syntax stx (symbolic-integral (syntax->datum #'expr) (syntax->datum #'var)))] |
98 |
| - [id (datum->syntax stx (gensym))]) |
99 |
| - #'(send this integral-helper (lambda () (send this wally-evaluate intgl)) 'id (interesting-time?)))] |
100 |
| - [(_ expr) ; default variable of integration is (milliseconds) |
101 |
| - (with-syntax ([intgl (datum->syntax stx (symbolic-integral (syntax->datum #'expr) '(milliseconds)))] |
| 102 | + (syntax-parse stx |
| 103 | + [(integral e:expr (~or (~optional (~seq #:var v:expr)) (~optional #:numeric) (~optional #:symbolic) (~optional (~seq #:dt d:expr))) ...) |
| 104 | + (with-syntax ([intgl (datum->syntax stx (symbolic-integral (syntax->datum #'e) |
| 105 | + (if (attribute v) (syntax->datum #'v) '(milliseconds))))] |
102 | 106 | [id (datum->syntax stx (gensym))])
|
103 | 107 | #'(send this integral-helper (lambda () (send this wally-evaluate intgl)) 'id (interesting-time?)))]))
|
104 | 108 |
|
| 109 | + |
105 | 110 | (define reactive-thing%
|
106 | 111 | (class abstract-reactive-thing%
|
107 | 112 | (super-new)
|
|
0 commit comments