HtDP: Problem 9.5.5

In problem 9.5.5, I knew I wasn’t understanding something. I thought that I had followed the recipe, yet I couldn’t solve the problem. That alone was a red flag indicating that I most probably did not follow the recipe!
In this discussion everyone helped me to see what I was missing. The thing was that I was missing something about recursion, the fact that you can figure out what you need to do by combining this thing with the rest of the things.
To specific, the step that I had skipped was literally taking the expected data and using that to determine the combination that needs to occur within the program body. Before, my approach had always been to solve “the whole problem” at once for the recursive step. Following the recipe, you can much more easily see what you are missing.

HtDP: Problem 10.1.9

In problem 10.1.9, I wanted to force a problem to be recursive when it really wasn’t. Matthias and Carl helped me see the difference here in the discussion that followed. Here are some notes:
Matthias:

In HtDP, the word “natural” is a technical word. It means
if your INPUT data definition has a self-reference in the Nth clause for the Kth field then your template has a recursion in the Nth cond clause for the Kth field.
Try this:
An RD is one of:
— ‘doll
— (cons RD empty)
Problem: design a function that counts the number of cons layers around ‘doll.

Carl:

what’s so recursion about it? To be less cryptic, if you read your purpose statement, and apply it to the recursive call, does it make sense? Are you really solving a smaller instance of the same problem, or are you just solving a smaller problem? The former is recursion; the latter is not (and suggests either inlining or a helper function).
For future reference, what I described is a way to tell after the fact whether what you wrote makes sense as recursion, but what Matthias described is the part of the design recipe that tells you whether to use it or not before you even start. Focus on what he said (and what’s in the book) for figuring out how to apply recursion, and you’ll find you can always answer what I asked with “yes”.

The essence of form abstraction

Formlets:

Abstraction is the cornerstone of high-level programming; HTML forms are the principal medium of web interaction. However, most web programming environments do not support abstraction of form com- ponents, leading to a lack of compositionality. Using a semantics based on idioms, we show how to support compositional form construction and give a convenient syntax.

Formlets are now also part of the PLT Web Server.
(via PLT)

Packed Binary Routines for PLT Scheme

Per Doug’s post:

I have implemented an equivalent of the Python pack/unpack functions in PLT Scheme. I needed it primarily to be able to (more easily) read binary data from other applications for analysis in PLT Scheme.

Here is what it does:

This module performs conversions between PLT Scheme values and C structs represented as PLT Scheme byte strings. It uses format strings (explained below) as compact descriptions of the layout of the C structs and the intended conversion to/from PLT Scheme values. This can be used in handling binary data stored in files or from network connections, among other sources.

Comment Boxes

Originally posted here:

In DrScheme you can comment out code either using semicolons or by using a “box”.
The way that it works is that you:
1. Select the code you want to put in a comment box.
2. Go to the Scheme menu and select Comment Out With a Box.
You may find this particularly useful when you get to the structure template definitions in chapter 6. It makes them much nicer to write, read, and maintain.

How you might implement the exercises

When you work on your exercises, you can leverage DrScheme to make it easier to find particular functions or bits of homework by using the definitions dropdown. I posted on it here:

Here is how I implement exercises. I say implement, because I am concerned here with a coding detail, *not* design recipes.
DrScheme has a nice feature in the top-left side of the window (roughly) called the “definitions dropdown”. Using this dropdown you can see all of the names you’ve got defined in the Interactions area.
So for example if you had entered (define x 10) in the Definitions are then you would see an entry in there that says “x”. You can leverage to make keeping track of your exercises easier. This is what I do, I keep all of my exercises in the same file as long as it makes sense to do so, and as part of that before every exercise I add something like this:
(define 2.3.2 true)
That tells me:
1. What my answer was for the exercise.
2. Whether or not it is finished.
That is how I keep all of my exercises in the same file and still have it make sense since each exercise creates any number of definitions!