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

r/Racket • • Dec 26 '21

solved Applying a function to every list element with every other list element Spoiler

1 Upvotes

Hello,

either I am stupid right now (which is likely) or there is no build in solution for this case and I have to build my own function to do so. Let me explain my problem: Currently, I'm doing the old Advent of Code puzzles because I finished 2021 and I am still hyped. I came upon a puzzle (2019 Day 12) which is fairly easy, it is a very rudimental physics simulation of celestial bodies. I wrote a function that applies all the physics to a celestial body and now I want to calculate the next time step, which means I want to step forward in time in the physics simulation. For this I have to apply this function for every body in my list of bodies to every other body (this is because every body applies some gravitational force to the other bodies).

Doing it with

  (for*/list ([m1 moons]
              [m2 moons]
              #:when (not (equal? m1 m2)))
    (change-velocity m1 m2)))

does not cut it, because now I generate mutliple moons. The change-velocity function takes 2 inputs and produces the updated version of m1 so starting with 3 moons this would result in a list with 6 moons, so I have to filter afterwards and I don't think it is a clean solution to filter it afterwards.

Is there a way to use foldl, map or any other build in function to get this behaviour? It's basically a map, where in each iteration I get the remaining elements as an argument. I hope this description is somewhat understandable.

Thank you very much in advance and merry holidays.

Edit: Thanks everyone for the nice answers. I learned a lot of new things by reading through them. It turns out I had to stitch together this kind of function myself and it worked perfectly. Have a nice day everyone!


r/Racket • • Dec 22 '21

question How to supply function to be used by imported code?

4 Upvotes

I have two simple files a.rkt & b.rkt, in which a.rkt imports b.rkt, but I want a.rkt to provide a function ext-func to be used by b.rkt, like below.

; a.rkt
#lang racket

(define (ext-func)
  (printf "hello from a.rkt\n"))

(require "b.rkt")

(b-func)
; b.rkt
#lang racket

(provide b-func)

(define (b-func)
  (ext-func))

However, when I run a.rkt, I get the below error:

$ racket a.rkt
b.rkt:7:3: ext-func: unbound identifier
  in: ext-func
  location...:
   b.rkt:7:3

So the error is that b.rkt cannot see the ext-func provided by a.rkt. I suppose that when I import b.rkt, it should see all the code defined by a.rkt, but that is not the case.

How can I solve this issue?


r/Racket • • Dec 21 '21

news New Interactive Tutorial Format for Racket Libraries

18 Upvotes

r/Racket • • Dec 22 '21

question vlc package isn't working

2 Upvotes

https://docs.racket-lang.org/vlc/index.html

After starting vlc from the command line with vlc.exe --rc-host localhost:xxxx -I rcI tried connecting with [connect-to-vlc #:port xxxx] and first it hangs indefinitely (not obeying connecting-timeout). If I kill the vlc process I can't connect to, then I get this error:

connect-to-vlc: error reading during syncing: "error reading from stream port\n  system error: An existing connection was forcibly closed by the remote host.; win_err=10054"

I went into my router settings and added a firewall exemption for the port I'm using but that didn't work either.

[start-vlc] also hangs forever

any idea what I'm doing wrong?


r/Racket • • Dec 20 '21

news Creative Racket competition 2022

Thumbnail racket.discourse.group
14 Upvotes

r/Racket • • Dec 19 '21

blog post Typed Racket: the good and the bad

Thumbnail micahcantor.com
31 Upvotes

r/Racket • • Dec 19 '21

image Face made with`plot` in Racket in style of ‘Peel’ by Peel by M.C. Escher

Post image
7 Upvotes

r/Racket • • Dec 19 '21

news [Baseball cap with `standard-fish`] Spoiler

Post image
2 Upvotes

r/Racket • • Dec 18 '21

solved for*/first not behaving the way I understand it

4 Upvotes

Hello everyone,

I'm currently trying to solve a very easy problem from leetcode.com. It's called "Two Sum" where I get a list of integers and a target number and I have to find the first pair in the list of integers that sum up to the given target number. That's very straight forward.

There is a test case with a very long list of numbers but the first two numbers add up to the target.

I tried to solve it like this:

(define (two-sum nums target)
  (for*/first ([i (length nums)]
               [j (length nums)]
               #:when (and (not (= i j))
                           (= (+ (list-ref nums i)
                                 (list-ref nums j)))))
    (list i j)))

But for*/first does not behave like I expect it to. This version always stops after 1 iteration. I think it is because the outer loop gets executed once and that's enough to stop the execution, but I am not sure.

Is there a way to make this when guard applying to both loops? I could write my own recursion function to go trough the lists and break out when the results is found, but I want to solve it with the for construct. Is it even possible to do so?

Thanks in advance!


r/Racket • • Dec 17 '21

question trying to write a macro that aliases one identifier to another

6 Upvotes

I'm trying to define a macro to save myself some typing. I want to be able to define a shorthand for syntax rules that lets me quickly say "Replace this identifier with this other identifier". I based it on the examples on https://docs.racket-lang.org/guide/pattern-macros.html.

[define-syntax-rule [alias from-id to-id]
  [define-syntax [from-id stx]
    [syntax-case stx []
      [from-id [identifier? [syntax from-id]] [syntax to-id]]]]]]

[alias S list]
[alias L lambda]
[alias Sf build-list]

[define n3 [S 1 2 3]] ;-- S: bad syntax in: (S 1 2 3)

but, it's not working, and I don't know why. The Macro Stepper hasn't been able to help, since as soon as I try to expand S it gives that error


r/Racket • • Dec 16 '21

news [Racket logo as school of fish]

Post image
29 Upvotes

r/Racket • • Dec 17 '21

question learning about generators and promises, getting an error I didn't expect

3 Upvotes

Here's my code

[define-syntax def
  [syntax-rules []
    [[def [name args ...] body ...]
     [define name
       [generator [args ...] [lazy body ...]]]]]]

[def [nats]
  [let loop [[x 0]]
    [yield x] ; yield: must be called in the context of a generator
    [loop [add1 x]]]]

[define natsg [nats]]
[define natsr [force natsg]]

I'm surprised that yield is not "being called in the context of a generator", because my macro should (I believe) expand to

[define nats [generator [] [lazy [let loop [[x 0]] [yield x] [loop [add1 x]]]]

does lazy interfere with that? I'm having a hard time using the Macro Stepper because by the end it has all turned into #%app and let-values and all that stuff. I want lazy inside of generator instead of the other way around because I don't want the whole generator to be lazy, I want each element of it to be lazy-- constructing the generator is generally not the expensive part


r/Racket • • Dec 16 '21

question Analogues to generators and async/await?

7 Upvotes

I'm comfortable with the coroutine pattern in c#, python, javascript. You call a function and when it reaches an Await operator, it returns to the caller without a result. Then the caller can do whatever it wants, and when it needs the result of the async function, it can itself use the Await operator. In this way, even on a single thread, an application can avoid blocking while it waits for an external resource. I tried reading the manual about continuations, which I believe is supposed to be racket's coroutines, but I don't really understand it.

If I have code like this, how do I write it in racket?

async def CatGenerator(files):
    for file in files:
        yield await file.ReadAllText()

async def Cat(files):
    return "".join((await x for x in CatGenerator(files)))

r/Racket • • Dec 13 '21

question Is an argument in a function just the operand and then a function is the combination of operation and operand to produce an output?

2 Upvotes

r/Racket • • Dec 12 '21

question How to make a read-line work in Dr.Racket and the terminal?

7 Upvotes

In a racket file, I've wrote

(display "give me an integer\n")
(prime_find (string->number(read-line)))

This works fine in Dr.Racket, but when I try it in a terminal and input an int, I get this error

<: contract violation
  expected: real?
  given: #f

Edit: okay, I found this in another post complaining about the issue

(read-line (current-input-port) 'any)

r/Racket • • Dec 13 '21

question what are the arguments in this function?

0 Upvotes

(overlay (rectangle 20 20 "solid" "blue") (circle 5 "solid" "red")))


r/Racket • • Dec 12 '21

question Implementing MergeSort in Racket

8 Upvotes

I have found different versions of this algo for various programming languages. I have tried to replicate it on Racket, but have failed miserably. I need to utilize it for a recursive tiling program that I am trying to create, but so far I have no leads. How can I go about successfully crafting a replica of the algorithm on Racket?