The Racket repository
![]() optional and add a contract that calls the 'draw' argument to make sure it restores the dc state. The call to the 'draw' function happens right when 'dc' is called and it tests the property that 'draw' doesn't abuse the state only that one time and only with x=0 and y=0. This seems likely to catch common errors, however, since the mismanagement of the state is unlikely to be related to the values of 'x' and 'y' and also unlikely to depend on the timing of the the call (i.e., if it happens at all, it probably always happens). Another way we could enforce this contract would be to wrap the `draw' argument so that each time it is called, we grab the state of the dc and compare it to afterwards. The current strategy is less expensive and also catches errors earlier (in the case of slidehow specifically, we'll get the errors during the startup of the presentation instead of when we try to render a slide (in the middle of the presentation, typically)). This change slows down calls to 'dc'. For example, this program: #lang racket/gui (require pict) (define brush (send the-brush-list find-or-create-brush "black" 'solid)) (define (circ w h) (dc (λ (dc dx dy) (define orig-pen (send dc get-pen)) (define orig-brush (send dc get-brush)) (send dc set-pen "black" 1 'transparent) (send dc set-brush brush) (send dc draw-ellipse dx dy w h) (send dc set-pen orig-pen) (send dc set-brush orig-brush)) w h)) (void (time (for/fold ([b (blank)]) ([i (in-range 10000)]) (vc-append (circ (random 1000) (random 1000)) b)))) goes from cpu time: 16 real time: 17 gc time: 0 to cpu time: 2166 real time: 2172 gc time: 224 on my machine. Still, that cost, when measured in a per-call-to-dc way is only .21 msecs, which seems reasonable given the pain of tracking down the kinds of bugs that this contract helps detect. |
||
---|---|---|
native-pkgs@60c510ba85 | ||
pkgs | ||
racket | ||
.gitattributes | ||
.gitignore | ||
.gitmodules | ||
.mailmap | ||
.travis.yml | ||
INSTALL.txt | ||
Makefile | ||
README.txt |
This is the source code for the main Racket distribution. See "INSTALL.txt" for information on building Racket. License ------- Racket Copyright (c) 2010-2014 PLT Design Inc. Racket is distributed under the GNU Lesser General Public License (LGPL). This means that you can link Racket into proprietary applications, provided you follow the rules stated in the LGPL. You can also modify Racket; if you distribute a modified version, you must distribute it under the terms of the LGPL, which in particular means that you must release the source code for the modified software. See racket/src/COPYING_LESSER.txt for more information.