r/Racket • u/sdegabrielle • Jul 06 '21
book Don’t Teach Coding: Until You Read This Book
“The definitive resource for understanding what coding is, designed for educators and parents”
r/Racket • u/sdegabrielle • Jul 06 '21
“The definitive resource for understanding what coding is, designed for educators and parents”
r/Racket • u/ws-ilazki • Nov 28 '19
r/Racket • u/Distinct-Brief9643 • Aug 23 '26
Simple syntax tho!
r/Racket • u/mimety • Nov 01 '22
It has always annoyed me that the operation of adding an element to the end of a list in Scheme is an "expensive" one, (unlike the operation of adding to the beginning of a list).
Of course, in standard Scheme, there is always a way to get over it, like this:
(define (list-builder)
(let ((mylist '())
(lastcell '()))
(lambda (m)
(case m
((append) (lambda (x)
(cond
((null? mylist)
(set! mylist (cons x '()))
(set! lastcell mylist))
(else
(let ((newcell (cons x '())))
(set-cdr! lastcell newcell)
(set! lastcell newcell))))))
((get) (lambda () mylist))))))Now we can do this:
> (define mylist (list-builder))
> ((mylist 'append) 1)
> ((mylist 'append) 2)
> ((mylist 'append) 3)
> ((mylist 'get))
> (1 2 3)But when we try to do the same in Racket, we can't because Racket doesn't support mutable lists.
Ok: truth be told, racket has mcons, mcar set-mcar!, set-mcdr!, etc, but in Racket those mutable lists are completely separate from regular lists and cannot be interchanged. This means that none of the functions for working with "classic" lists can be used over mutable lists, which really sucks!
I don't know about you, but to me this is a totally strange decision by the creators of Racket, because, as far as I know, the idea of Scheme is not only to be a functional language, but also to have its imperative side, too. I don't understand why Racket gets away with it and discourages the use of mutable list wherever it can?
r/Racket • u/mgamal92 • Mar 09 '20
r/Racket • u/Icy_Pressure_9690 • Dec 11 '21
(string=? "design" "tinker")
r/Racket • u/sdegabrielle • Mar 27 '24
r/Racket • u/Gelate98 • Jun 17 '15
I need help to design a function that consumes two images and produces true if the first is larger than the second. but they have to be primitive images (triangles and the like)... please help me, cause I am totally lost on how to do this, I am not sure how to do this T_T is due to me being new at this
r/Racket • u/kawad23 • Feb 15 '19
CSAS 1114: Introduction to Program Design I
Homework 2: Greeting
DUE Friday, Feb 15th by 11:59pm
Overview
Write a function that takes time in military format and the user’s first name.
a) The function should create appropriate greeting message that includes user’s name.
b) If the number was not in the right range, print: “I don’t understand this time! Are you in another dimension?”
c) Call the function for following inputs:
a. Your name, 1605
b. Alien, 20543
d) Use check-expect to test your program
Note 1: Follow this format for greeting:
Good morning = 0:00 - 12:00
Good afternoon = 12:01 - 17:00
Good evening = 17:01 - 24:00
Note 2: Here is the time in military format
Military – Regular
Military – Regular
0001 – 12:01 am
1300 – 1:00 pm
0100 – 1:00 am
1400 – 2:00 pm
0200 – 2:00 am
1500 – 3:00 pm
0300 – 3:00 am
16:00 – 4:00 pm
0400 – 4:00 am
17:00 – 5:00 pm
0500 – 5:00 am
1800 – 6:00 pm
0600 – 6:00 am
1900 – 7:00 pm
0700 – 7:00 am
2000 – 8:00 pm
0800 – 8:00 am
2100 – 9:00 pm
0900 – 9:00 am
2200 – 10:00 pm
1000 – 10:00 am
2300 – 11:00 pm
1100 – 11:00 am
2400 – 12 Midnight
1200 - Noon
Example:
Input: Justin, 200
Sample Output: Good morning, Justin!
Submission
Submit your DrRacket code via blackboard under lab “Greeting”.
Guideline:
Program should begin with a header comment that provides the name of the homework, the name of the author, the date, and a short description of the program.
I created these conditions so far:
(define (greeting mtime name)
(cond
[(and (<= 0 mtime) (<= 1200 mtime)) "Good Morning"]
[(and (< 1201 mtime) (<= 1700 mtime)) "Good Afternoon"]
[(and (< 1701 mtime) (<= 2400 mtime)) "Good Evening"]
[else "I don’t understand this time! Are you in another dimension?"]))
But I am confused about how to use string-append and how to call these conditions. If I made a mistake above, please feel free to correct it. Thank you!
r/Racket • u/hElLoWoRLD292 • Mar 15 '23
(define (sn-empty)
(sn-empty)
'())
I have been trying to print an empty list.
The input:
> sn-empty
output:
()
Please explain what I am doing wrong in the code above.
r/Racket • u/[deleted] • Oct 23 '19
A “DrRacket” group is present on FB, you’re welcome!
Someone told me it was a bad idea but I did it anyway, there’s 146 members as of now.
r/Racket • u/AgencyPure7878 • 6d ago
I've been having some issues in understanding concepts in CS, and although I've gone to tutoring and gotten my grade up a bit, knowing and understanding base concepts would help significantly, especially since we do cover material very quickly. My test tomorrow is exclusively on recursion, specifically tail and non-tail. I've been able to complete non-tail recursions correctly for the study guide given, but am having a bit of a harder time with the tail recursions (below). I also need to go over if and cond statements, which I can do correctly but don't have an entirely firm grasp of, and the basic syntax - things like memorizing quotient, remainder, modulo etc. The questions are :
7. Write a tail-recursive function sum-of-squares, where a <= b, that computes: a ^ 2 + (a + 1) ^ 2 + (a + 2) ^ 2 + ... + b ^ 2. You may write a helper function.
Write a procedure that computes the sum of the squares of every integer from a to b:
a² + (a+1)² + (a+2)² + … + b²
For example, (sum-of-squares 2 4) computes 2² + 3² + 4² = 4 + 9 + 16 = 29.
Your solution must be tail-recursive: the recursive call must be the very last thing the procedure does, with nothing left to compute after it returns.
a. The helper: (sum-of-squares-helper a b acc)
b. The wrapper: (sum-of-squares a b), the wrapper should contain no recursion of its own.
Examples:
(sum-of-squares 1 1) => 1
(sum-of-squares 5 5) => 25
(sum-of-squares 1 3) => 14
(sum-of-squares 2 4) => 29
8. Write a tail-recursive function that computes x ^ n (x to the power of n). Name your function power-n.
For example, (power-n 2 3) computes 2 × 2 × 2 = 8.
Your solution must be tail-recursive.
a. The helper: (power-helper x n acc)
b. The wrapper: (power-n x n). The wrapper should contain no recursion of its own.
Examples:
(power-n 2 0) => 1
(power-n 2 1) => 2
(power-n 2 3) => 8
I can answer these on my own, so please do not give the answers, but provide a very basic explanation - visual if possible - and label each component. Thank you!
r/Racket • u/Sir_Lochloy • Oct 09 '22
r/Racket • u/Distinct-Brief9643 • Aug 31 '26
r/Racket • u/Unusual-Hat-1617 • Oct 16 '22
Hi, how can I create list of lists. Method (append '() '(1) '(1 1 1)) return list of ints, but I need something like this: ('() '(1) '(1 1 1))
(define/contract (generate numRows)
(-> exact-integer? (listof exact-integer?))
(define (pascal-triangle n)
(define (build-row r)
(list (if (null? (cdr r))
(car r)
(list (+ (car r) (cadr r)) (build-row (cdr r))))))
(let build-triangle (\[lst-storage '()\] \[lst '(1)\] \[n2 n\])
(if (eq? n2 0)
lst-storage
(build-triangle
(append lst-storage lst)
(flatten (list (first lst) (build-row lst)))
(sub1 n2)))
)
)
(pascal-triangle numRows)
)
(generate 5)
r/Racket • u/Nyanraltotlapun • Aug 14 '18
I am in the search of package/code for creating I2P application.
r/Racket • u/SecuredKnowledge • May 28 '22
Is it possible to set x equal to the built-in function sqr? If so what would that look like?
Edit: How would you make a string consisting of "sqr" perform it's mathematical function instead?
r/Racket • u/VortexHDG • Mar 25 '20
i need to write a for loop function that iterates over a list and counts the number of items in the list
Please be kind and help me
if you could tell me how to do it would be very much appreciated.
r/Racket • u/[deleted] • Feb 13 '19
r/Racket • u/jstquestions • Sep 11 '18
I tried (define x 3) but that isn't working. I tried other versions of that but still no cigar.
r/Racket • u/larvike • Dec 26 '14
r/Racket • u/sdegabrielle • Aug 09 '20
I’m not saying Scheme is bad - Scheme is great. Just that Racket has a lot of extras, both in the language and surrounding tools.
e.g. did you know raco pkg migrate 7.7 will move everything you had installed in 7.7 into your current version(7.8).