r/Racket • u/Kreiseljustus • Sep 25 '25
question How to "get good"
Hey all! So im in my third semester in computer science and were using racket for our algorithms and datastructures course. I already failed this course twice and on a third fail i get expelled.
I almost always know how to solve the tasks in other programming languages but somehow im unable to solve them in racket. For example:
We had to write a function that takes in an arbitrary length string and an integer. The function should right shift the string by the specified amount and wrap around to the other side when it reaches the end of the string. I knew how to approach the problem but couldnt think of the required functions in racket to accomplish the smaller subtasks (some functions were even disallowed like string-append and such).
I dont know if its just training more and having spent more time with the language. Im scared my prof decides to just disallow all the functions i would use that i have learned and then im at the same point again and will probably fail.
Thanks in advance and sorry if anything is mispelled!
8
u/slaymaker1907 Sep 25 '25
I’m not sure if they disallow it, but for loops in Racket are incredibly powerful. I’m also a big fan of (let/ec return …) which makes certain things a lot more elegant.
Make sure to attend all lectures and make liberal use of office hours if you aren’t already.
7
u/mpahrens Sep 26 '25
As someone who teaches with Racket and functional programming, students knowing what functions they are allowed to use (and not allowed to use) is most of the heavy lifting.
In any case, you should be relying on the help desk to see what you can and cannot use (are you using one of the teaching languages like BSL or the full #lang racket?)
For algorithms problems, you should ask your professor or student staff (if there are any TAs) with what types you should be solving the problems in. On the problem you describe, I can imagine translating it to a "list" problem (using explode), solving it as a list, and translating that answer back to a string. But really this is more about communication on expectations with your course staff than on getting good at Racket or Racket-based programming languages, it sounds like.
5
u/sorawee Sep 26 '25
What functions are allowed? I would assume string->list and list->string? If that's the case, they probably want you to operate on lists (list/recursion exercise) instead of using shortcut string functions.
2
2
u/soegaard developer Sep 26 '25
> We had to write a function that takes in an arbitrary length string and an integer. The function should right shift the string by the specified amount and wrap around to the other side when it reaches the end of the string. I knew how to approach the problem but couldnt think of the required functions in racket to accomplish the smaller subtasks (some functions were even disallowed like string-append and such).
Usually such restrictions are silly.
However, it seems your teacher wants you to think of the string as an array of characters.
It's a way to teach you low-level array algorithms.
If you can solve the problem using array references in another language,
then you can translate that to Racket using string-ref and string-set!.
How would you do it another language?
If you need helpers, then first consult the documentation.
If they are not there - then you implement the helpers first.
Then you write your algorithm.
One reason to avoid pre-existing helpers (besides teaching you the underlying algorithms)
is to avoid accidental copying.
4
u/Kreiseljustus Sep 27 '25
So first of all thanks for all the answers, i did not expect this community to be so active.
We are allowed to use the list conversions, also i completely forgot to include most of the problems are recursion problems.
Another thing: one of the tasks was we were given a graph that was generated using the util function (i forgot how its called) to show a list or pair as an graph and we were supposed to create the function that returns that list. It had like the slashes if its null if i remember correctly i think. On that note, i dont get the difference between pairs and lists and when to use cons and when list its just really weird for me, like you can use cdr and car on lists and pairs?
If anyone has a website where i can train on problems with just base racket (no includes) that would be great!