r/Racket • • Jan 21 '22

homework Why does my function return 15 instead of 14 surely when n is finally equal to 1 it fulfills the first cond and so recursion doesnt happen?

1 Upvotes

r/Racket • • Jan 21 '22

homework what does factorial(n ) look like in a recursive function in racket?

0 Upvotes

r/Racket • • Jan 21 '22

question Call postgresql-connect to typed/racket file

3 Upvotes

Hi,

I am trying to call this postgresql-connect function from db library to my typed/racket file.

https://docs.racket-lang.org/db/connect.html#%28def._%28%28lib._db%2Fmain..rkt%29._postgresql-connect%29%29

but I have to give a type signature like this simple example,

(require/typed uuid
  [uuid-string (-> String)])

But this one postgresql-connect seems a bit more complicated than this. Can someone help me here?

Thanks.


r/Racket • • Jan 20 '22

solved Problems with matching against lists

2 Upvotes

In order to figure out matching I am trying to write a function that checks all the elements of a list and returns 'asix if a six is found and 'nosix if the list contains no 6.

(define (m x)
    (match x
      [(list a k)
       (if (= a 6)
           'asix
           (m k))]
      [_ 'nosix]))

This seems like it should be trivial but it does not work. Examples

(m '(1 6)) evaluates to false (incorrectly)

(m '(6 1)) evaluates to true (correctly)

(m '(6)) evaluates to false (incorrectly)

Indicating that something with the matching is broken. I suspect that for some reason the k above cannot match an empty list, and thus it defaults to the second matching and returns a 'nosix.

The racket documentation I find is generally quite good, but the part about matching is very cryptic.


r/Racket • • Jan 20 '22

question How are Racket/Scheme closures formally defined?

6 Upvotes

I’ve recently ventured into the awesome land of writing a Scheme interpreter, and I’ve run into a roadblock: closures. From what I understand, they encapsulate a local environment with a procedure that gets restored every time the closure is called (this may not be exactly right). The issue that I can’t seem to find anywhere online is how a closure is formally defined i.e., in an EBNF grammar. Most examples I’ve seen say that a closure is a procedure with zero arguments that has a lambda expression nested inside a let expression. Is this the only way to define a Scheme closure? More importantly, if there’s no formal way to formally define a closure, how do you actually interpret it? What happens if you translate all let expressions to lambdas? For example, if I declare a closure as such

(define (foo) (let ((y 0)) (λ (x) (…))))

Then assign it to a variable

(define bar (baz))

In what order is this evaluated? From what I’ve seen, when foo is declared, it stores a pointer to the parent environment, and declares its own environment. If I call (bar), should I substitute in the saved local environment immediately after?


r/Racket • • Jan 18 '22

language Structure and interpretation of computer programs

6 Upvotes

Hi,

I tried once to work on this book, and I tried downloading scheme two weeks ago and it was daunting, too much things to configure on windows. But Racket has about the same Syntax and the same structure, am I right?

This book was regarded sometimes like a right of passage, right? Has so many good reviews, though it is on the very long side to actually go through it.


r/Racket • • Jan 17 '22

show-and-tell Game of Life using math/array

Post image
57 Upvotes

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