[racket] simple question from newb

From: Michael Coppola (coppola.mi at husky.neu.edu)
Date: Fri Dec 10 23:04:44 EST 2010

Hi David,

big-bang's (stop-when) takes a procedure as an argument, so you need to
give it either a lambda with your expression, or define your expression
as a new function and pass it the function's name.  When you just give
it an expression (like in your code), it's evaluating to either true or
false and passes it as the argument to stop-when.

  (define (main ws)
    (big-bang ws (on-tick tock) (to-draw render) (stop-when (lambda (ws)
(> ws 500)))))

should fix it.  Or try:

 (define (end? ws)
   (> ws 500))

  (define (main ws)
    (big-bang ws (on-tick tock) (to-draw render) (stop-when end?)))

Hope that helps.  If you have any other questions, feel free to ask.

Regards,
MC

On 12/10/2010 10:40 PM, David Taub wrote:
> Wrote this from the lesson:
>
> ;; this is the definitive exercise 32 from the 2htdp
> ;; car moves across the empty-screen.  Yay.  12/2/2010
>
>
> ;;  this creates the empty window
>
> (define WIDTH 1000)
> (define HEIGHT 40)
> (define MTSCN (empty-scene WIDTH HEIGHT))
>
> ;; this draws the vehicle shape
>
> (define WHEEL-RADIUS 5)
>   (define WHEEL-DISTANCE (* WHEEL-RADIUS 5))
>   (define BODY-LENGTH (+ WHEEL-DISTANCE (* 6 WHEEL-RADIUS)))
>   (define BODY-HEIGHT (* WHEEL-RADIUS 2))  
>    (define WHL (circle WHEEL-RADIUS "solid" "black"))
>   (define BDY
>     (above
>       (rectangle (/ BODY-LENGTH 2) (/ BODY-HEIGHT 2)
>                  "solid" "blue")
>       (rectangle BODY-LENGTH BODY-HEIGHT "solid" "red")))
>   (define SPC (rectangle WHEEL-DISTANCE 1 "solid" "white"))
>   (define WH* (beside WHL SPC WHL))
>   (define CAR (underlay/xy BDY WHEEL-RADIUS BODY-HEIGHT WH*))
>   
>   ;; As Ramin A. my old classmate once said, "I drew a tree"
>   ;; Well, this is a tree I was instructed to place in the empty screen
>   ;; as a constant shape throughout the running fo the program
>   
>   (define tree
>     (underlay/xy (circle 10 'solid 'green)
>                  9 15
>                  (rectangle 2 20 'solid 'brown)))
> ;; this one actually places the tree!
>   
>    (define BACKGROUND
>      (place-image tree 500 25 MTSCN)
>      )
>    
> ;; this sets the y-axis (vertical) for the car and
> ;; defines the "tock" where the trigger is the clock (not keystroke or
> mouse)
> ;; increments of 3
>    
>   (define Y-CAR 30)
>   (define (tock ws) (+ ws 3))
>   
> ;;  Here we are placing the car into the scene, according to the given
> world state
>
>   (define (render ws) (place-image CAR ws Y-CAR BACKGROUND))
>  
>   
>  
> ;;  here is the big-bang, or main program, that is the actual instruction 
> ;; to use all the above-definitions
>   
>   (define (main ws)
>     (big-bang ws (on-tick tock) (to-draw render) *(stop-when (> ws
> 500)  )*))
>
> ;;  that's it!  
> ;;  next step is a condition that will stop the program when 
> ;; the vehicle reaches a certain point
>
> ****************************
> Ok, I bold-faced the attempt to have the car stop at x-axis of 500,
> which I believe is ws 500.  When I put in "(main 1)" in the execution
> line, I get a false boolean, if I put in "(main 501)" I get a true
> boolean.  Both cases, it doesn't work the "procedure expects an
> argument", not a true/false.  
>
> How the heck can I get the stop-when function to work, or can I be
> pointed to a section of the tutor or other reference that explains to
> me what should be a simple (not to me) additional command in the
> big-bang.  Thank you in advance,
>
> dt
>
> -- 
>
> CONFIDENTIAL EMAIL:  This email may contain - Attorney-Client
> Privileged - Attorney Work Product - This email is only for use by the
> intended recipient. If received in error any use, disclosure or
> copying is prohibited. Any inadvertent receipt shall not be a waiver
> of any privilege or work product protection. If you have received this
> communication in error, please notify sender immediately.  Thank you.
>
>
> _________________________________________________
>   For list-related administrative tasks:
>   http://lists.racket-lang.org/listinfo/users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20101210/129924be/attachment.html>

Posted on the users mailing list.