Re: [racket-users] How to apply side effects to all elements in a list
Yes! John just taught you how to fish. > On Mar 22, 2017, at 3:51 PM, 'John Clements' via Racket Users > wrote: > > >> On Mar 22, 2017, at 12:45 PM, Angus wrote: >> >> I am a bit stuck on rendering images in a list. >> >> Here is my code below. >> >> (require 2htdp/image) >> >> (define-struct bear-state (x y rotation size)) >> >> (define MTS (empty-scene WIDTH HEIGHT)) >> >> BEAR-IMAGE is just a graphic - of a bear. >> >> (define (render-bear b) >> (place-image (scale (bear-state-size b) (rotate (bear-state-rotation b) >> BEAR-IMAGE)) (bear-state-x b) (bear-state-y b) MTS)) >> >> >> >> (define (render-bears bears) >> (cond [(empty? bears) (place-image (square 0 "outline" "white") 0 0 MTS)] >> [else >> (render-bear (first bears)) ; can render 1 bear >> (render-bears (rest bears))])) >> >> >> render-bear works but I can't get render-bears to work. What am I doing >> wrong? Any hints? > > Rendering bears is quite dangerous. I’m surprised you got even one to work. > More than that is just asking for trouble. > > (Sorry, I’m tired. I do see the problem in your code. I bet you can solve > this problem using the stepper, and a test case.) > > John Clements > > > > -- > You received this message because you are subscribed to the Google Groups > "Racket Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to racket-users+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] How to apply side effects to all elements in a list
Hi Angus Usually it helps to start by getting something simple to work and then little-by-little adding more. E.g. Here's a working example with squares instead of bears, and limited to just varying rotation ... #lang racket (require 2htdp/image) (define blue-square (square 25 'solid 'blue)) (apply beside (for/list ([i 18]) (rotate (* 20 i) blue-square))) Dan -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] How to apply side effects to all elements in a list
> On Mar 22, 2017, at 12:51 PM, 'John Clements' via Racket Users > wrote: > >> On Mar 22, 2017, at 12:45 PM, Angus wrote: >> >> render-bear works but I can't get render-bears to work. What am I doing >> wrong? Any hints? > > Rendering bears is quite dangerous. I’m surprised you got even one to work. > More than that is just asking for trouble. > > (Sorry, I’m tired. I do see the problem in your code. I bet you can solve > this problem using the stepper, and a test case.) Angus, what happens when you try writing your program in one of the teaching languages, like Beginning Student Language? Those were designed to help programmers when they make beginner-type mistakes. Also, the stepper John Clements is referencing is only available in the teaching languages. Alex Knauth -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] How to apply side effects to all elements in a list
2thdp/image isn't effectful; images are values. You need to combine the image you get from rendering one bear with the image you get from rendering the rest of the list. You can do so using one of the combiners provided by the library: (combiner-of-choice (render-bear (first bears)) (render-bears (rest bears))) (possibly with some extra arguments thrown in) - Sam Caldwell On Wed, Mar 22, 2017 at 3:45 PM, Angus wrote: > I am a bit stuck on rendering images in a list. > > Here is my code below. > > (require 2htdp/image) > > (define-struct bear-state (x y rotation size)) > > (define MTS (empty-scene WIDTH HEIGHT)) > > BEAR-IMAGE is just a graphic - of a bear. > > (define (render-bear b) > (place-image (scale (bear-state-size b) (rotate (bear-state-rotation b) > BEAR-IMAGE)) (bear-state-x b) (bear-state-y b) MTS)) > > > > (define (render-bears bears) > (cond [(empty? bears) (place-image (square 0 "outline" "white") 0 0 MTS)] > [else > (render-bear (first bears)) ; can render 1 bear > (render-bears (rest bears))])) > > > render-bear works but I can't get render-bears to work. What am I doing > wrong? Any hints? > > -- > You received this message because you are subscribed to the Google Groups > "Racket Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to racket-users+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] How to apply side effects to all elements in a list
> On Mar 22, 2017, at 12:45 PM, Angus wrote: > > I am a bit stuck on rendering images in a list. > > Here is my code below. > > (require 2htdp/image) > > (define-struct bear-state (x y rotation size)) > > (define MTS (empty-scene WIDTH HEIGHT)) > > BEAR-IMAGE is just a graphic - of a bear. > > (define (render-bear b) > (place-image (scale (bear-state-size b) (rotate (bear-state-rotation b) > BEAR-IMAGE)) (bear-state-x b) (bear-state-y b) MTS)) > > > > (define (render-bears bears) > (cond [(empty? bears) (place-image (square 0 "outline" "white") 0 0 MTS)] >[else > (render-bear (first bears)) ; can render 1 bear >(render-bears (rest bears))])) > > > render-bear works but I can't get render-bears to work. What am I doing > wrong? Any hints? Rendering bears is quite dangerous. I’m surprised you got even one to work. More than that is just asking for trouble. (Sorry, I’m tired. I do see the problem in your code. I bet you can solve this problem using the stepper, and a test case.) John Clements -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[racket-users] How to apply side effects to all elements in a list
I am a bit stuck on rendering images in a list. Here is my code below. (require 2htdp/image) (define-struct bear-state (x y rotation size)) (define MTS (empty-scene WIDTH HEIGHT)) BEAR-IMAGE is just a graphic - of a bear. (define (render-bear b) (place-image (scale (bear-state-size b) (rotate (bear-state-rotation b) BEAR-IMAGE)) (bear-state-x b) (bear-state-y b) MTS)) (define (render-bears bears) (cond [(empty? bears) (place-image (square 0 "outline" "white") 0 0 MTS)] [else (render-bear (first bears)) ; can render 1 bear (render-bears (rest bears))])) render-bear works but I can't get render-bears to work. What am I doing wrong? Any hints? -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.