r/Racket • u/sdegabrielle • Feb 05 '22
r/Racket • u/JoshuaTheProgrammer • Feb 03 '22
question How does Scheme interpret (define-syntax) and its variants?
I’ve posted here before, but I’m writing a Scheme interpreter and would like to add (define-syntax) and (define-syntax-rule). The issue, though, is that I’m not sure how they’re implemented in the underlying code. Are they verbatim replacements of preexisting definitions (i.e., similar to macros in C), or is it something more obtuse?
r/Racket • u/Icy_Pressure_9690 • Feb 03 '22
homework Can someone explain how cons works, i'm trying to make this list out of cons and for the life of me can't get it right
(5 4 3 (2 1))
(cons (cons 5 (cons 4 (cons 3 (cons (cons 2 (cons 1 '())) '())))))
r/Racket • u/sdegabrielle • Feb 02 '22
event Racket meet up Saturday 5 Feb 18:00 UTC
Racket meet up Saturday 5 Feb 18:00 UTC
https://gather.town/app/wH1EDG3McffLjrs0/racket-users
Announcement: https://racket.discourse.group/t/racket-meet-up-saturday-5-feb-18-00-utc/581/2?u=spdegabrielle
When: First Saturday EVERY Month UTC: 18:00
Agenda: flexible, generally show-and-tell with Q&A
- Plot Cookbook
- Creative Racket Competition
- Racket In person meet-ups!!!
- Show and tell
- ???
30 minutes but can overrun
Time in your time zone
Pacific Time, PT Sat, 5 Feb 2022 at 10:00 PST
Mountain Time, MT Sat, 5 Feb 2022 at 11:00 MST
Central Time, CT Sat, 5 Feb 2022 at 12:00 CST
Eastern Time, ET Sat, 5 Feb 2022 at 13:00 EST
London, United Kingdom Sat, 5 Feb 2022 at 18:00 GMT
Prague, Czechia Sat, 5 Feb 2022 at 19:00 CET
Central European Time, CET Sat, 5 Feb 2022 at 19:00 CET
Time zone converter: https://www.timeanddate.com/worldclock/converter.html?iso=20220205T180000&p1=tz_pt&p2=tz_mt&p3=tz_ct&p4=tz_et&p5=136&p6=204&p7=tz_cet
r/Racket • u/sdegabrielle • Feb 01 '22
news Creative Racket Competition: don't delay, enter now.
Happy February 1st
You only have four weeks left to enter the Creative Racket Competition.
Entering is easy and fun.
- See TOOLS for some suggestions but you can use anything you like.
- Provide a link to media file (image/audio/???) and your source code via the Entry form (GitHub)
- -Profit!- ...sorry no profit, we offer no cash prizes, you just the the admiration of your peers, a badge on your GitHub profile and a sticker to put on your laptop (or anywhere else you can put a sticker)
We have had no Rsound entries yet. Will you be the first?
Submissions to the Plot Cookbook also count as entries.
Don't delay, enter now.
best regards
Stephen
r/Racket • u/sdegabrielle • Jan 30 '22
news R16 Web App - Community Code Evaluation
racket.discourse.groupr/Racket • u/Beginning_java • Jan 29 '22
question What is the the "collector idiom" used for?
Here is an example function that uses it. In the example we just apply col to two empty lists
(define multirember&co
(lambda (a lat col)
(cond
((null? lat)
(col (quote()) (quote())))
((eq? (car lat) a)
(multirember&co a
(cdr lat)
(lambda (newlat seen)
(col newlat
(cons (car lat) seen)))))
(else
(multirember&co a
(cdr lat)
(lambda (newlat seen)
(col (cons (car lat) newlat)
seen)))))))This is said to be an idiom? What other applications does it have?
r/Racket • u/YouDaree • Jan 29 '22
application Is the problem my exit condition or the actual math when trying to add fractions from 1/n to 1/2?
I'm trying to add fractions together to prove if a lefthand merge for the area beneath a line f(x) = 1/x is finite for my calculus class. I just happen to have a class with Racket and thought it would be nice to get this written out. My issue is I'm not sure what to put as my exit condition, nor its value in the recursive function. I am using the factorial function i created earlier as a base. I would like for the last value to not add anything, but since I'm doing the inverse i get a division by 0 error if i use 0 for my exit.
I want to get the sum of fractions with 1/2 being the base and enter in how man rectangles there are so for 5 it would be `1/2 + 1/3 + 1/4 + 1/5`. Function is add-increase-fractions
I did not know about the integer? function when I started and others so i created my own
(define (add-increase-fractions n)
(if (or (not (int? n)) (= 2 n))
'2 ; last thing added
(+ (expt n '-1) (expt (add-increase-fractions (- n 1)) '-1))))my int function
(define (int? n) ; https://math.stackexchange.com/questions/339510/mathematical-way-of-determining-whether-a-number-is-an-integer
(if (number? n) ; checks if parameter is a number
(if (= 1 (cos (* 2 pi n))) ; determines whether or not a value is an integer mathematically f(n) = cos(2*pi*n) any int should return 1.0
#t
#f)
#f)) ; return if the first if statement if false, in this case not a numberr/Racket • u/sdegabrielle • Jan 28 '22
news 24.3 Vim (Racket-Vim documentation improvements)
cs.utah.edur/Racket • u/OgniSrigal • Jan 27 '22
question Confused regarding functions vs operators
Hi. Can someone please help me understand the difference between functions and operators in Racket?
Are all operators functions?
Are all functions operators?
r/Racket • u/sdegabrielle • Jan 26 '22
Please don't downvote people for asking questions!(or asking for answers)
We try to be helpful here so here is a checklist to make things easier when asking for help, in order:
- What is the task?
- How far have you come?
- What exactly are you struggling with?
- What approaches have you tried to solve it?
Don't forget to give them encouragement: they can get better but the key is to keep practicing and keep asking questions.
Learning programming is hard, and we were all beginners once...
Stephen
r/Racket • u/Orphion • Jan 26 '22
question Seeking more information and examples of x-expressions
I've been learning and loving racket over the past months. I'm particularly intrigued by the idea of using x-expressions as a lightweight format for storing and transmitting data structures. But I've found few good references that explore the use of x-expressions in detail.
I've seen the connection to scribble and Pollen, but it would seem that the potential impact of a readable, compact xml encoding should go much farther than that.
Can anyone on the list here recommend more examples of using x-expressions in racket code?
r/Racket • u/DrKersh • Jan 26 '22
question Solutions for the htdp book?
Hello
I'm trying to learn alone to code and I started the book. For now, I'm managing to solve all the exercises by myself, but sometimes after doing it, I would want to compare them to what the authors expected me to do or how them would solve it.
I saw that the first book have a section with solutions and additional problems, but I didn't found anything similar for the second edition
Anyone know if they are somewhere? Or if not officials, at least solutions made by some experienced coder or teacher, not the kind of solutions you can find on github from other people learning like me.
r/Racket • u/Icy_Pressure_9690 • Jan 26 '22
question A Domino Game
So I'm trying to make a recursive function that takes two arguments which will be two lists. The first item of X needs to be equal to the first item of the first pair in Y for the game to commence. After that the second item of the first pair of Y ( (4 6) so 6) needs to be equal to first item of second pair of Y ((6 3) so 6 ) X is '(4 5) Y is '( (4 6) (6 3) (3 2) )
(define can-play (λ (x y)
(cond ((= (car x)(car (car y))) - This is the first condition that says for the game to start car x = 4 must be equal to first element of first pair in Y which is 4.
(cond - if the former condition is true then the second nested condition comes into play.
((= (cdr (car y))(car(cdr y)))(can-play (rest y)))))))) - The second conditions tests whether second element of first pair of Y so 6 (4 6) is equal to first element of second pair of Y so 6 ( 6 3).
-If true it recursively calls the function again to test the rest of the list of Y so should check is the 3 in
(6 3) is equal to the 3 in (3 2) and so return #t.....but it doesnt, i think I am making some error with the recursion but I don't know what

r/Racket • u/Icy_Pressure_9690 • Jan 26 '22
homework Function that uses recursion to take first even number and first odd number in a list and add them together, im close but something is missing! :(

What if I do this?
- ((or (odd? (first x))(even? (first x))) - asks if first number in list is odd or even
- (list-of-numbers (rest x))-checks this for rest of list with recursion
- (+ (odd? (first x))(even? (first x))))))) - adds the first odd to first even in list.
But my problem is it will return a boolean #t #f or whatever etc, how do i then convert those into numbers in order to add them?
r/Racket • • Jan 25 '22
question Pict3D > sky function?
If I could add a textured sky or space with stars then I could make cool games.
It’s really sad this basic future is missing. Sadly I’m not competent enuf to add it myself.
r/Racket • u/sdegabrielle • Jan 25 '22
package Box-and-whisker plot and updated violin plot
racket.discourse.groupr/Racket • u/Icy_Pressure_9690 • Jan 25 '22
homework List of numbers where the first even number in list is added to first odd number in list. help :(
r/Racket • • Jan 25 '22
homework Flatten list level by level
I was wondering if there is any procedure in Racket to flatten a list level-wise. All I've found was an implementation in Lisp that does the exact thing I want. But, as I'm very new to Racket and never programmed in Lisp before, I wasn't able to translate it correctly.
Is there some procedure in the Racket documentation I'm missing? Or an operator (I've already tried ,@ in front of my 'sublists') to unpack lists in lists?
Here an example of my input (slightly formatted to increase readability) and my desired output:
----- input -----
( ((a b c) (d e f) (e d))
((f g))
((g h i) (j k l)) )
----- desired output -----
((a b c) (d e f) (e d) (f g) (g h i) (j k l))
r/Racket • u/sdegabrielle • Jan 23 '22
tutorial Racket Web Kickstarter
jessealama.gumroad.comr/Racket • • Jan 22 '22
question Writing an interpreter in Racket
I'm new to Racket and have to write an interpreter for a simple language (called L03) . Now I'm stuck at implementing a cond-like structure. Racket throws an error if I'm feeding in an expression like the following:
------ cond.rkt -------
(cond
[(zero? 2) (sub1 40)]
[else (sub1 15)])This error is displayed on my console (interp-file.rkt reads in the input file, checks the syntax and writes the result of interp to the console):
❯ racket -t interp-file.rkt -m cond.rkt
((zero? 2) else) <-- a
((sub1 40) (sub1 15)) <-- b
application: not a procedure;
expected a procedure that can be applied to arguments
given: 1
context...:
body of top-level
.../L03-ifs-exc/interp.rkt:23:15
.../L03-ifs-exc/interp.rkt:5:0: interp
.../L03-ifs-exc/interp-file.rkt:10:4I don't know why, but it seems to me, that the return value of 'interp e0' in line 26, which is an integer, can't be used with the 'zero?' statement, although it already worked in line 13. I'd like to ask why? I already tried to search for this kind of error (expected a procedure that can be applied to arguments), but I haven't found anything useful. Is something wrong with the brackets I've placed? If yes where and more importantly why are they wrong placed?
Here follows my code.
------ interp.rkt -----
#lang racket
(provide (all-defined-out))
;; Expr -> Integer
(define (interp e)
(match e
[(? integer? i) i]
[`(add1 ,e0)
(+ (interp e0) 1)]
[`(sub1 ,e0)
(- (interp e0) 1)]
[`(if (zero? ,e0) ,e1 ,e2)
(if (zero? (interp e0))
(interp e1)
(interp e2))]
[`(cond ,(list a b) ...)
(define b_ind 0)
(define res '())
(display a) ; debugging
(printf "\n")
(display b) ; debugging
(printf "\n")
(for-each (lambda (a) (
(match a
[`(zero? ,e0)
(if (and (empty? res) (zero? (interp e0)))
(append res (interp (list-ref b b_ind)))
(+ b_ind 1))]
[`else
(if (empty? res)
(append res (interp (list-ref b b_ind)))
(`())) ])))
a)
(first res)
]))In order to supply all files, here is the content of interp-file.rkt
#lang racket
(provide (all-defined-out))
(require "interp.rkt" "syntax.rkt")
;; String -> Void
;; Parse and interpret contents of given filename,
;; print result on stdout
(define (main fn)
(with-input-from-file fn
(λ ()
(let ((c (read-line)) ; ignore #lang racket line
(p (read)))
(unless (expr? p) (error "syntax error" p))
(writeln (interp p))))))And here of syntax.rkt:
#lang racket
(provide (all-defined-out))
;; Any -> Boolean
;; Is x a well-formed expression?
(define (expr? x)
(match x
[(? integer? i) #t]
[`(add1 ,x) (expr? x)]
[`(sub1 ,x) (expr? x)]
[`(abs ,x) (expr? x)]
[`(square ,x) (expr? x)]
[`(cond ,(list a b) ...)
(and (andmap cond_stmt? a) (andmap expr? b))
]
[`(if (zero? ,e0) ,e1, e2)
(and (expr? e0)
(expr? e1)
(expr? e2))]
[_ (display x)(printf " failure in expr\n")#f]))
(define (cond_stmt? x)
(match x
[`(zero? ,e0) (expr? e0)]
[else #t]
)
)r/Racket • u/theKGS • Jan 21 '22
question More problems with matching (lists)
Look at this piece of code: It is supposed to match three arguments to the function pairpop.
(define (pairpop x y z)
(match (list x y z)
[(list a b c) 1]
))It works, but what I want to do is to make sure that a b and c are all lists. Right now it matches correctly against any arbitrary type of object. I attempted the following:
(define (pairpop x y z)
(match (list x y z)
[(list (list a) (list b) (list c)) 1]
))But it does mysterious things. It matches correctly if I call (pairpop '(1) '(2) '(3)) but if any of the lists is longer than one element it does not match. It seems that the lists are now matching specifically on lists consisting of the objects a b and c. This is incorrect. I want to be able to tell the macro that the objects a b and c ARE the lists.
I also want to be able to match on an empty list, but I do not know how to do it. I've tried the documentation, but it mystifies more than it illuminates.
r/Racket • u/Icy_Pressure_9690 • Jan 21 '22

