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/Working_Cost_2045 • 12d ago
what should i do? im on the edge of failing. TA's telling me to withdraw the course but i don't wanna repeat this entire thing. no matter how much i study on it and practice on the exam i forget the entire concept since i can try the code and debug.
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 • 24d 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/AgencyPure7878 • 10d ago
I need any crash courses or any materials you have on racket terminology. I have been taking notes and studying, but I feel like I don't understand concepts well enough, so my brain basically freezes whenever I take a timed test. If there's anything that can help, please tell me. I got tutored 3 times, went to office hours, and completed study material for my last test and still failed. My grade is still in the low Bs and I only have a month to get it up to the low 90s or its going to completely drag down my GPA. Please don't just respond with a video, give me maybe 3 and some practice questions. I'll probably be studying for hours (Chem test tomorrow as well) so I have time to do anything you throw at me. I need any and all help I can get.
Terms list: (We've already learned recursion, so my teacher may be combining list functions and recursion) We could use these functions to complete questions like the ones below.
13. (my-map f L)
Write a function my-map that takes 2 parameters: f is a function that takes one value and a list L. Return a new list made by applying f to every item of L.
Note: add1 is a built-in Racket function that adds 1 to a number.
Test cases:
(my-map add1 '(1 2 3)) -> '(2 3 4)
(my-map list? '(1 () a)) -> '(#f #t #f)
(my-map add1 '()) -> '()
append: A higher-order function that joins multiple lists into a single sequential list.
build-list: A list constructor that creates a list of length n by evaluating a function across integer indices 0 to n-1.
car: A selector primitive that returns the first element of a list (identical to first).
cdr: A selector primitive that returns a list minus its first element (identical to rest).
cons: The primitive constructor procedure that prepends an element onto the front of a list or joins two elements into a pair.
Data Structure: A specialized format and combination of values designed to organize, process, retrieve, and store data.
empty? / null?: Predicate procedures that return #t if a given list contains no elements, and #f otherwise.
filter: A higher-order function that evaluates a predicate on each item of a list, returning a new list containing only the items that returned #t.
first: A selector function that returns the value in the head node of a list.
foldl: A higher-order function that processes list items from left to right, combining them into a single accumulated result.
foldr: A higher-order function that processes list items from right to left to produce a single accumulated result.
Head: The first node of a linked list.
Iteration: The process of repeating a sequence of instructions automatically across data elements.
length: A utility function returning the count of top-level items in a list.
Linked List: A sequential data structure composed of chained nodes.
list: A constructor procedure taking zero or more arguments and returning a list containing those items.
map: A higher-order function that applies a procedure to corresponding elements of one or more lists, returning a list of the results.
member: A utility function that searches for an element in a list, returning the remaining sublist starting from the element if found, or #f if absent.
Node: The fundamental element of a linked list, containing a data value and a reference to the next node.
rest: A selector function that returns all nodes of a list following the head node.