<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: zeh</title>
    <description>The latest articles on DEV Community by zeh (@zephyr_teresa_a4d7f3db9f7).</description>
    <link>https://dev.to/zephyr_teresa_a4d7f3db9f7</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3686806%2F5148adcc-1583-49a4-a06c-b40c4f5a48f1.png</url>
      <title>DEV Community: zeh</title>
      <link>https://dev.to/zephyr_teresa_a4d7f3db9f7</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/zephyr_teresa_a4d7f3db9f7"/>
    <language>en</language>
    <item>
      <title>HTDP Study Blog</title>
      <dc:creator>zeh</dc:creator>
      <pubDate>Wed, 31 Dec 2025 02:32:17 +0000</pubDate>
      <link>https://dev.to/zephyr_teresa_a4d7f3db9f7/htdp-study-blog-1nh5</link>
      <guid>https://dev.to/zephyr_teresa_a4d7f3db9f7/htdp-study-blog-1nh5</guid>
      <description>&lt;p&gt;This blog is a comprehensive study guide distilled from many past exams (2019–2024) and lecture rules in HTDP / Racket. It focuses on evaluation, function design, data-driven templates, recursion, abstraction, local/closure, and common exam traps.&lt;/p&gt;

&lt;p&gt;note:&lt;/p&gt;

&lt;p&gt;This blog was summarized from the everyday notes and mistake summary by me while writing racket programs and revising for exams. Its sole purpose is to help write clear, readable, and collaboration-friendly code, and to understand the underlying execution model of Racket programs. It does not cover the three algorithm-focused chapters (for example, graphs, accumulators, and search).&lt;/p&gt;

&lt;p&gt;For those algorithmic chapters, the most important advice is: go through past papers by yourself. Separate blog posts will be written later to specifically cover the algorithmic content in HTDP.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Evaluation Questions (Step-by-Step Reduction)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Core Rules&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Substitute all parameters at once.&lt;/li&gt;
&lt;li&gt;Substitute constants defined by define one by one, in order.&lt;/li&gt;
&lt;li&gt;For cond, reduce the condition first, then evaluate the chosen branch.&lt;/li&gt;
&lt;li&gt;For or, the first true stops evaluation.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Always run the program to confirm the final value.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Function Debugging Questions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Common Fixes&lt;/p&gt;

&lt;p&gt;a. Predicate functions must end with ?&lt;br&gt;
b. check-expect needs enough variance (larger, smaller, and same cases)&lt;br&gt;
c. String stubs usually return an empty string, not false&lt;br&gt;
d. (number? x) already returns a Boolean, so do not wrap it with if&lt;br&gt;
e. If you test button-down, also test button-up&lt;br&gt;
f. Run first, read the error message, then inspect the function body&lt;/p&gt;

&lt;p&gt;Frequent Bugs&lt;/p&gt;

&lt;p&gt;a. Swapped coordinates in selectors&lt;br&gt;
b. Using the wrong selector (x vs y)&lt;br&gt;
c. Stub does not match the function signature&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HTDD (How to Design Data)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Rules&lt;/p&gt;

&lt;p&gt;a. The last condition in cond should use else&lt;br&gt;
b. If the data is self-referential, the template must recurse&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HTDW (World Programs)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Key Events&lt;/p&gt;

&lt;p&gt;Handle key events using a cond on the key value, with a final else case that returns the unchanged world.&lt;/p&gt;

&lt;p&gt;Tips&lt;/p&gt;

&lt;p&gt;a. The render function must be defined before big-bang&lt;br&gt;
b. Keep false handling consistent across event handlers&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reference and Recursion Questions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Self vs Mutual Reference&lt;/p&gt;

&lt;p&gt;a. Self-recursive: a function calls itself&lt;br&gt;
b. Mutual-recursive: functions call each other&lt;/p&gt;

&lt;p&gt;Trust Natural Recursion&lt;/p&gt;

&lt;p&gt;Once the first element is correct, trust the rest.&lt;br&gt;
Do not repeatedly re-check (first (rest ...)).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Empty Base Cases (VERY IMPORTANT)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;sum of an empty list returns 0&lt;br&gt;
product of an empty list returns 1&lt;br&gt;
append with an empty list returns empty&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Abstraction and Higher-Order Functions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Choosing the Right Abstract Function&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use map or filter when the goal is to produce a list&lt;/li&gt;
&lt;li&gt;Use foldr or foldl when the goal is to aggregate values&lt;/li&gt;
&lt;li&gt;Use build-list when generating a list based on indices&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Function Signatures&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;map: takes a function from X to Y&lt;/li&gt;
&lt;li&gt;filter: takes a function from X to Boolean&lt;/li&gt;
&lt;li&gt;foldr: takes a function from X and Y to Y&lt;/li&gt;
&lt;li&gt;build-list: takes a Natural number to X&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Common Error&lt;/p&gt;

&lt;p&gt;Do not call a function when passing it as an argument.&lt;br&gt;
Pass the function name itself.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Local, Closure, and Lifting&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Closure Definition&lt;/p&gt;

&lt;p&gt;A function is a closure if:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It is a function&lt;/li&gt;
&lt;li&gt;It uses variables not listed in its parameters&lt;/li&gt;
&lt;li&gt;Those variables come from an outer scope&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Evaluation Cost&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Definitions outside loops are evaluated once&lt;/li&gt;
&lt;li&gt;Definitions inside loops are evaluated on every iteration&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Genrec (Generative Recursion)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Must Include&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A base case&lt;/li&gt;
&lt;li&gt;A reduction step&lt;/li&gt;
&lt;li&gt;A termination argument&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Common Mistake&lt;/p&gt;

&lt;p&gt;A wrong base case leads to incorrect images or values.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Well-Formed Data Definitions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Not well-formed:&lt;br&gt;
A data definition that directly contains itself with no base case.&lt;/p&gt;

&lt;p&gt;Well-formed:&lt;br&gt;
A data definition that includes a base case and a recursive reference.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Helper Functions — When Are They Needed?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Use a helper function when:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Referencing non-primitive nested data&lt;/li&gt;
&lt;li&gt;Performing two-phase processing&lt;/li&gt;
&lt;li&gt;Switching knowledge domains&lt;/li&gt;
&lt;li&gt;Handling arbitrary-sized data such as lists or trees&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Parameters vs Arguments vs Operands&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Parameter: a name in a function definition&lt;br&gt;
Argument: a value passed to a function call&lt;br&gt;
Operand: an input to an operator&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Exam Survival Checklist&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Follow the template strictly&lt;br&gt;
Match signature letters exactly&lt;br&gt;
Always consider the case where rest is empty&lt;br&gt;
Order cond clauses carefully&lt;br&gt;
Only write function names in function positions&lt;br&gt;
Do not call functions when passing them as arguments&lt;br&gt;
Always run the code&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Final Advice&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Design correctly, then trust recursion.&lt;/p&gt;

&lt;p&gt;HTDP exams reward discipline, templates, and precision, not clever hacks. I personally feel very rewarded as a beginner through learning these basic design principles and extending them in future programming as a behaved and cooperative programmer.&lt;/p&gt;

</description>
      <category>computerscience</category>
      <category>learning</category>
      <category>racket</category>
    </item>
  </channel>
</rss>
