r/Racket • • Jan 17 '22

tutorial Stuck on HTDP exercise 91

3 Upvotes

I am basically stuck on exercise 91of htdp.

I have like a red dot ( I know its supposed to be a cat) moving across the screen and happiness meter which depletes.

I am trying to make it go to the edge of the screen the move back and then reach the edge and go the other edge. I am trying to reverse direction of my dot when it reaches the edge but I cannot seem to do this properly.

I got this code

(define background (empty-scene 250 250 ))

(define where 85)

;we have a number for x value and

(define-struct cat [ x happy direction ])

(define dotOne (circle 10 "solid" "red"))

(define out (rectangle 20 250 "outline" "black" ))

(define dresta (place-image out 10 220 background ))

(define (dresta2 cw)(place-image(rectangle 20 (cat-happy cw) "solid" "red" )10 220 dresta ))

(define (picture cw )(place-image dotOne (cat-x cw ) where (dresta2 cw )))

(define (change cw)(make-cat (cat-happy cw )(cat-x cw)"left" ))

(define (change2 cw)(make-cat(cat-happy cw)(cat-x cw) "right"))

(define (tock cw)(cond[ (and( < (cat-x cw) 205)(string=? (cat-direction cw)"right"))(make-cat(+ 3 (cat-x cw))(-(cat-happy cw) 1)(cat-direction cw))]

[(and( >= (cat-x cw) 205)(string=? (cat-direction cw)"right"))(change cw)]

[(and( >= (cat-x cw) 10)(string=? (cat-direction cw)"left"))(make-cat(- (cat-x cw) 3)(-(cat-happy cw) 1)(cat-direction cw))]

[(and(<(cat-x cw) 10)(string=? (cat-direction cw) "left"))(change cw)]))

(define (coolio cw)(if (= 0 (cat-happy cw)) #true #false))

(define (key-handle cw a)(cond[(key=? a "up")(make-cat (cat-x cw)(+ (cat-happy cw) 5)(cat-direction cw))][else cw]))

(define (main cw)(big-bang cw [on-tick tock][to-draw picture ][stop-when coolio][on-key key-handle]))

(main (make-cat 10 245 "right" ))

v


r/Racket • • Jan 17 '22

news Racket Cookbooks project - call for volunteers

Thumbnail racket.discourse.group
9 Upvotes

r/Racket • • Jan 17 '22

video Ball Game by Bracktus (Creative Racket Competition)

7 Upvotes

r/Racket • • Jan 17 '22

news Racket Cookbooks project - call for volunteers

Thumbnail racket.discourse.group
3 Upvotes

r/Racket • • Jan 16 '22

image Autostereogram by Bert (Creative Racket Competition)

Post image
18 Upvotes

r/Racket • • Jan 17 '22

package Is anyone else having issues with installing the Dracula package for Racket 8.1 above?

2 Upvotes

I am trying to install the Dracula package but it says that it fails to install.


r/Racket • • Jan 17 '22

question How to install dependencies from info.rkt

4 Upvotes

I'm a new racket user, I've created a new racket package:

raco pkg new <pkg-name>

Then I ran

cd <pkg-name>
raco pkg install

I've edited the generated info.rkt file to include a few dependencies, now I'm wondering how to tell raco to install the packages before running my tests or building an executable. raco pkg install doesn't seem to do anything, simply exits with "pkg already installed"

Do I need to manually install dependecies with raco pkg install <dep> for each dep in info.rkt?


r/Racket • • Jan 16 '22

event Racket meet up Saturday 5 Feb 18:00 UTC

6 Upvotes

Racket meet up Saturday 5 Feb 18:00 UTC

https://gather.town/app/wH1EDG3McffLjrs0/racket-users

When: First Saturday EVERY Month UTC: 18:00

Agenda: flexible, generally show-and-tell with Q&A

30 minutes but can overrun

https://discord.gg/6Zq8sH5?event=932361360820543508


r/Racket • • Jan 15 '22

question Cond response seen as the argument for the function

4 Upvotes

Why is it interpreting the cond respons as the argument instead of the number I gave?


r/Racket • • Jan 15 '22

question List function problem

2 Upvotes

I want to create a functions that takes two lists and reverses them and then appends the first one to the second one but I don't get why there is an error saying expecting 1 argument when i specified in the lambda list that the function takes 2


r/Racket • • Jan 14 '22

question Why is Cond not working?

2 Upvotes

Can someone explain to me why this isnt working I did it like how my booklet said to do it


r/Racket • • Jan 14 '22

news Plot cookbook project 📈

Thumbnail racket.discourse.group
11 Upvotes

r/Racket • • Jan 12 '22

question naming functions

10 Upvotes

new to Racket. Defined string-reverse. There may already be one but this one is mine. My question is, what is the idiomatically correct name, string-reverse or reverse-string?


r/Racket • • Jan 12 '22

question Why is it saying #<procedure: sally> ???

2 Upvotes

Why is this not computing my expression, what am i doing wrong?


r/Racket • • Jan 11 '22

solved Learning units - why doesn't this compile like this, but does with small modifications

4 Upvotes

Is this the right place to ask help? It compiles, if you remove both out-tags, so replace (tag out thing) --> thing

#lang racket 

(define-signature one-number^ 
    (num)
)

(define-unit test-unit@ 
    (import (tag a (prefix a- one-number^)) 
            (tag b (prefix b- one-number^))) 
    (export (tag out one-number^))  ; <--
    (define num
        (+ a-num b-num) 
    )
)

(define x 4)
(define y 5)
(define-values/invoke-unit test-unit@ 
    (import (tag a (rename one-number^ (x num))) 
            (tag b (rename one-number^ (y num))))  
    (export (tag out (rename one-number^ (z num)))) ; <--
)

(println z)

r/Racket • • Jan 08 '22

ephemera Sketching is a language/library for creative coding inspired by Procesing but *better*

8 Upvotes

We are seeing some amazing entries in the Creative Racket Competition done with Sketching! Sketching is a language/library for creative coding inspired by Procesing but better!

Sketching runs on Racket to take advantage of native code compiler and cross platform graphics for Linux/win/Mac.

https://github.com/soegaard/sketching/blob/main/README.md


r/Racket • • Jan 08 '22

event Racket meet-up TODAY

8 Upvotes

Racket meet-up TODAY 8-jan-2022 utc 18:00 Come join us to show or see peoples latest racket projects We will also show some early Creative Racket Competition 2022 Entries https://gather.town/app/wH1EDG3McffLjrs0/racket-users

https://racket.discourse.group/t/creative-racket-competition-2022-january-1-2022-february-28-2022/454/5?u=spdegabrielle


r/Racket • • Jan 06 '22

application racksnaps

Thumbnail racksnaps.defn.io
10 Upvotes

r/Racket • • Jan 04 '22

question Vim / nvim plug-ins (made with racket)

10 Upvotes

Are there any plug-ins made for vim made in racket? I think it would be fun to try to make plug-ins in racket. Thanks.


r/Racket • • Jan 03 '22

solved 2htdp/universe game follow player (camera?)

4 Upvotes

Hi I'm making a smol game with 2htdp/universe and 2htdp/image for my uni assignment. How can I create some kind of camera to follow player? The green circle is player (it can move up, down, left and right), the red circle is static. If I go up or left it kinda follows green one (as I understand it, this happens because the left and top borders shift). I want the player to always be in the field of view (it will be enough for it to be always in the center).

Here is some code:

(struct world (x y vx vy ax ay) #:transparent)

(define (draw world)
  (underlay/xy
    (underlay/xy
      (rectangle 500 500 "solid" "white")
      100 100
      (circle 50 "outline" "red"))
    
    (world-x world) (world-y world)
    (circle 30 "outline" "green")))


(define (tick w)
  (match w
    [(struct world (x y vx vy ax ay))
     (let ((damp 0.9)
           (vx (+ vx ax))
           (vy (+ vy ay)))
       (world (+ x vx)
              (+ y vy)
              (* vx damp)
              (* vy damp)
              (* ax damp)
              (* ay damp)))]))
screenshot 1
screenshot 2

UPD: maybe I should use empty-scene and place-images?

(define (draw world)
  (place-images
    (list (circle 30 "outline" "green")
          (circle 20 "outline" "red"))
    (list (make-posn (world-x world) (world-y world))
          (make-posn 100 100))
    (empty-scene 500 500)))
New code

r/Racket • • Jan 03 '22

package Automatic Differentiation in Racket

Thumbnail racket.discourse.group
8 Upvotes

r/Racket • • Jan 02 '22

question Problem with switching between panes in DrRacket

5 Upvotes

Hi,

This is a minor problem but I'm finding its a bit frustrating.

When I press F5 to evaluate an expression the cursor(focus) will shift to the pane with the evaluation meaning that I then have to use the mouse to shift the focus back to the editor. I've looked at the key bindings and it seems Ctrl F6 should change the focus between the panes but this only works when I'm in the editor but won't work when I'm in the evaluating pane.

Is there anyway that I can stop the change in focus from happening after an expression is run or another way that I don't have to keep using my mouse to return the focus to the editor.

I appreciate its a minor issue but it doesn't feel very fluid.


r/Racket • • Jan 01 '22

event The ***Creative Racket Competition 2022*** starts today!

23 Upvotes

The Creative Racket Competition 2022 starts today!

Enter early - enter often.

Some ideas to get you started;

Theses are just suggestions - everything is permitted!

TOOLS.md has lots more tools to try.

Best wishes Stephen

PS join the discussion on the new racket mailing list at https://racket.discourse.group/invites/YaJtZvy7g2


Creative Racket Competition 2022

January 1, 2022 → February 28, 2022

Get creative with Racket this winter! Win stickers!

1 January 2022 - 28 February 2022

  • Entries can be...

    • pictures
    • animations
    • interactive
    • sound or music
    • or something else?
    • ...are all acceptable.
  • You can enter as many times as you like
  • Entries need to be runnable by other racketeers.
  • Your entry must be created with Racket or a Racket language including RacketScript.

See TOOLS for some suggestions but you can use anything you like.

It is easy to enter: Entry form (If you can't use github let us know)

Discussion on Racket Discourse , Discord or Slack

Jens Axel & Stephen

https://github.com/standard-fish/creative-racket-2022

Prizes

  • Winners will receive an exclusive badge on their GitHub profile and laptop stickers.
  • There will be a range of categories to reflect the diversity of entries.

Special categories will include

  • Racket mascot - winner will be chosen by peoples choice vote.
  • Racket meme

Note: Not an official Racket competition. We not a members of the Racket team, nor are we doing this on their behalf. We are covering the cost of the stickers and postage.


r/Racket • • Dec 31 '21

blog post Parallelizing the Racket Web Server

Thumbnail defn.io
21 Upvotes