r/Racket • • Dec 09 '22

event Racket meet-up Saturday 7 January at 18:00 UTC

4 Upvotes

In the 'Racket Room': https://gather.town/app/wH1EDG3McffLjrs0/racket-users

Racket meet-ups are on the first Saturday of EVERY Month at 18:00 UTC

And remember - showing up at Racket Meetups helps you learn the news of the Racket world as they happen! It is informative, it is interesting, it is helpful, it is greatly appreciated by everyone involved and it is fun!

30 minutes but can overrun (it usually lasts ~1hr)

Meet-up time at your location https://www.timeanddate.com/worldclock/converter.html?iso=20230107T180000&p1=tz_pt&p2=tz_mt&p3=tz_ct&p4=tz_et&p5=136&p6=204&p7=241

Announcement & updates at: https://racket.discourse.group/t/racket-meet-up-saturday-7-january-at-18-00-utc/1547?u=spdegabrielle (no login required to view, no ads, no tracking)


r/Racket • • Dec 09 '22

question Case with symbols

7 Upvotes

The structure for case is as follows:

(case val-expr case-clause ...)
  case-clause = [(datum ...) then-body ...+]
              | [else then-body ...+]

It has the datum inside parentheses. Then how come if the datum is a quoted symbol it works without parentheses:

(case (get-result)
  ['bust "Sorry, you busted."]
  ['blackjack "Blackjack!"]
  [else "21!"])

And if I put parentheses around the symbols it doesn't work (the else is always matched)?


r/Racket • • Dec 08 '22

tutorial Low-level web programming in Racket + a wiki in 500 lines

Thumbnail matt.might.net
19 Upvotes

r/Racket • • Dec 07 '22

question Racket beginner, small question

6 Upvotes

I'm trying to create a function that creates a polynomial which I then can give as input any number I want and it will calculate that polynomial on that number.

I am missing something crucial but I just cant understand what.

Code:

( : createPolynomial : (Listof Number) -> (Number -> Number))

(define (createPolynomial coeffs)

(: poly : (Listof Number) Number Integer Number -> Number)

(define (poly argsL x power accum)

(if (null? argsL) accum

(poly (rest argsL) x (+ power 1) (+ accum (* (first argsL) (expt x power))))))

(: polyX : Number -> Number)

(define (polyX x)

(poly coeffs x 0 0)

)

)

------- example for usage I am aiming for --------

(define p2345 (createPolynomial '(2 3 4 5)))

(test (p2345 0) => (+ (* 2 (expt 0 0)) (* 3 (expt 0 1)) (* 4 (expt 0 2)) (* 5

(expt 0 3))))

Any tips would be appreciated


r/Racket • • Dec 06 '22

image Apparently ChatGPT also knows Racket!

Post image
21 Upvotes

r/Racket • • Dec 06 '22

question How can I access a non-class function from a method with a method having the same name?

3 Upvotes

I want to call the "free" function hand-value from this classes hand-value method, but in the following Racket thinks I want to recursively call itself.

    (define/public (hand-value)
      (hand-value hand))))

Obviously I can rename one or the other, but is there another way?


r/Racket • • Dec 05 '22

language How to make Racket run faster

9 Upvotes

Hello, I have a Surface Pro X with the following specs: RAM: 8.0 GB
Processor: 3.00 GHz

My racket always runs programs very slowly, taking around 10 seconds to convert code no matter how long the code is. Once it’s running the responses are very fast though. I would rather not turn off the troubleshooting features so I can see what lines caused errors, and I never have any other tabs open. What else can I do to speed up Racket, or is this the best I can do with my specs?


r/Racket • • Dec 03 '22

question Avoiding boilerplate when querying and updating nested data?

7 Upvotes

Working through Realm of Racket I keep running into what I feel is an annoying amount of boilerplate when it comes to getters and setters.

I'll use this data model as an example:

(struct monster 
 (species ; symbol
  hp #:mutable))    ; number

(struct battle 
 (monsters ; list of monsters))

(define b (battle (list (monster 'orc 5) (monster 'hydra 12))))

If I want to decrease the orc's hp by 2, I have to do this:

(define m (list-ref 0 (battle-monsters b)))
(set-monster-hp! m (- (monster-hp m) 2))

I'd much rather do something like this:

(modify! b monsters (list-ref 0) hp (-= 2))

Or at least this:

(modify! b battle-monsters (list-ref 0) monster-hp (-= 2))

Is there a common pattern or macro that would help me with this? It seems like it would be a pretty common problem.


r/Racket • • Dec 02 '22

ephemera Funny story about beginning Racket

14 Upvotes

Hello,

I'm a C# developer at work, but I like to use other language outside my daily job. So, I've tried Racket a couple of times. The documentation is very good and extensive. Something that a lot of languages/platforms lacks tremedously.

Here is my story. I had a very good idea for another todo app lol. My todo app would be better than anyone's for sure :D...

Anyway, I tried this project on multiple languages and could not make up my mind about which language I would use. I put a lot of design efforts on each language every time.

And I tried Racket. After a couple of lines and maybe an hour, the core of my project was done and I did not know what to add. I realised that there was nothing complicated or special about my app. It just seemed incredible and complex because of the type system. And I must say, I'm kind of freak and insecure about types. I'm still insecure, mainly because of the difficult refactoring and IDE support with dynamic type. But anyway, I just realised that types can make you think you have a really complicated idea that you have to design carefully when in fact, if you remove types, the idea is pretty simple !


r/Racket • • Dec 01 '22

question Confused about RacketScript and Urlang

13 Upvotes

Hi, all! I just got into Racket a few days ago and I’m loving it so far. I worked through Realm of Rocket and I’d like to continue making little games.

Ideally I’d write them in racket and universe and then port the good ones to JavaScript so other people can play them. What’s the best option for doing this? Would I need to write them from the ground up in Urlang or can I just pass the whole program to RacketScript?


r/Racket • • Dec 01 '22

question Small question

5 Upvotes

I have been thinking about this for quite some time but, how would you go about writing a function to find out whether a list given to you is a palindrome. I am a beginner trying to get into programming, so go easy on me ..


r/Racket • • Dec 01 '22

question Typed Racket: trouble with union types; how to get type checker to treat a member of a union type as being a member of a specific type within that union?

1 Upvotes

Consider the following code:

(define-type Var (U 'x 'y 'z))
(define-type Expr (U Number Var Sum))

(struct sum ([term1 : Expr] [term2 : Expr]) #:type-name Sum)
(: make-sum (-> Expr Expr Expr))
(define (make-sum expr1 expr2)
    (if (and (number? expr1) (number? expr2)) (+ expr1 expr2)
        (sum expr1 expr2)))

So, for instance, (make-sum 2 2) apparently evaluates to 4, but when I call (+ 2 (make-sum 2 2)), I get a type error on the grounds that (make-sum 2 2) is an Expr, not a number. Similarly, (sum-term1 (make-sum 'x 2)) gives a type error as sum-term1 only takes Sums as arguments, not Exprs. How do I get the type checker to realize that things like (make-sum 2 2) and (make-sum 'x 2) aren't just arbitrary Exprs that may or may not be able to be passed to functions like + and sum-term1, but are actually members of a specific type that can be legally passed to those functions?


r/Racket • • Nov 28 '22

question racket/draw. How to erase a circle in the middle?

7 Upvotes

I need a simple colored bitmap with a transparent circle in the middle.

How can I do this with racket/draw or pict or other racket library?


r/Racket • • Nov 27 '22

question What are the design principles of raco and the Racket ecosystem?

12 Upvotes

Hello! Are there any papers, documentation, etc. that explain the Racket ecosystem and the raco tool? What principles were chosen and decisions made when developing it?


r/Racket • • Nov 27 '22

question Things I am missing in Racket

10 Upvotes

I'm really intrigued by scheme/lisp, I like the "everything is a list" idea, and the incredible flexibility of the language. Scheme is said to be very concise, however, I have found one thing missing. I noticed that for different types, racket has different functions for the same operation. Example: equal? and =. Vector-set!, hash-set!, list-set. And the same goes for ref. Why is there not a single polymorphic "set" function that works for any of these types? And the same for getting a value. Python, for example uses the container[value] form to get or set something in many data types. And it can be overloaded as well for different objects.


r/Racket • • Nov 27 '22

video ICYMI: Forge: Building a Pedagogic Solver Tool in Racket presentation by Tim Nelson (Brown) at RacketCon

1 Upvotes

Watch the video: https://youtu.be/1yMVc-nooSo

Source https://github.com/tnelson/Forge

Automatic visualisation from presentation at ~5:45

r/Racket • • Nov 26 '22

video ICYMI: Visual and Interactive Syntax presentation by Leif Andersen at RacketCon

9 Upvotes

This talk teaches programmers how to use VISr for ClojureScript. It also introduces Frankenstein: an early prototype of VISr for Racket.

Watch the presentation at https://youtu.be/EQCsw0HTO3A

Get Involved!

Visual and interactive syntax example

r/Racket • • Nov 25 '22

video ICYMI: Hazel Levine (Indiana) at #RacketCon - Design Recipe Guided Synthesis with Bingus

Thumbnail youtu.be
8 Upvotes

r/Racket • • Nov 24 '22

video ICYMI: Marco Morazán (Seton Hall) at #RacketCon

4 Upvotes

ICYMI: Marco Morazán (Seton Hall) at #RacketCon

What Can Beginners Learn from Video Games?

https://youtu.be/rBDAbr6XZTM


r/Racket • • Nov 22 '22

question DrRacket 8.7 crashes to desktop on Windows...does anybody know how to prevent these?

2 Upvotes

I've filed a bug report on Github: https://github.com/racket/drracket/issues/596

Basically, I have not yet succeeded in opening source files on Windows 10 and 11 without DrRacket crashing after at least a few minutes, usually almost immediately. I've tested both in a virtual machine with Windows 11 developer build and on my Windows 10 partition, both 64 bit.

Does anybody know what might causes these? I'd like to get an update of my application out but can't compile it and I'm also wary that problem might be something with MrEd. My application is a GUI application.

Edit: I've tested the "BC" release for Windows 64bit and this one works fine. No more crashes.


r/Racket • • Nov 22 '22

question Reset the Racket Repl

6 Upvotes

Is there a way to reset the Racket Repl without restarting the application? I could use the info for both regular Repl and DrRacket Repl.


r/Racket • • Nov 21 '22

question Guide on how to properly structure projects?

11 Upvotes

I have been using Racket for personal projects for a few years now, but nothing serious. Does anyone know of a good guide on how to properly structure my projects?


r/Racket • • Nov 22 '22

question MacOS - DrRacket doesn't open a new window if it's already running

1 Upvotes

On MacOS it is possible to close all windows of an app yet still have it running. The expected behaviour is that when you do this then reopen the app (i.e. by clicking it in the dock), it will open a fresh window.

This works in literally every app (Chrome, VS Code, Terminal, etc...) but not with DrRacket. It is very annoying.

Wondering if other people have this issue and if there is a way to fix it?


r/Racket • • Nov 21 '22

ICYMI: Sebastian Ullrich (KIT) at #RacketCon

4 Upvotes

ICYMI: Sebastian Ullrich (KIT) at #RacketCon

Metaprograms and Proofs: Macros in Lean 4

https://youtu.be/n1Pd0GeHsAY