On Oct 20, 2011, at 1:20 AM, John Clements wrote:

> I'm pleased to report that the sound library works pretty transparently with 
> the universe teachpack.
> ...
> (define (accelerate b)
>  (cond [(and (<= (ball-posn b) 6)
>              (<= (ball-vel b) 0)) 
>         (begin (play pop)
>                (make-ball 6 (- (ball-vel b))))]
>        [else
>         (make-ball (+ (ball-posn b) (ball-vel b))
>                    (- (ball-vel b) 1))]))
> ...
> The larger question could potentially be whether the sound-playing should be 
> less imperative. If you wanted, you could add a "to-play" along with 
> "to-draw", and just make the sound-playing part of the world state. This 
> would avoid the "begin".


"to-play" MIGHT be a good way to do things, but in many cases (including the 
above "accelerate" example) it'll be more natural to specify a sound as you 
determine the new world, rather than as a separate function of the state of the 
world.  It's analogous to the difference between "stop-when" and "stop-with".  
One could provide this ability very simply:

(define (play-with sound world)
      (begin (play sound) world))

Are there other options or arguments to "play" that would need to be fit in 
here?

For example, there ought to be an easy way to turn off whatever sound is 
playing, perhaps by passing #f as the sound.


Stephen Bloch
sbl...@adelphi.edu


_________________________________________________
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users

Reply via email to