Questions tagged [htdp]

HtDP refers to the book "How to Design Programs". Use this tag both for questions concerning exercises from the book and for questions regarding the teaching HtDP teaching languages in DrRacket. https://htdp.org/

HtDP refers to the book "How to Design Programs".

Use this tag both for questions concerning exercises from the book and for questions regarding the teaching HtDP teaching languages in DrRacket.

https://htdp.org/

48 questions
1
vote
1 answer

How to ignore side-effect in Racket from using `set!`?

In Exercise 35.4.2 from HtDP, I've implemented the GUI and have a button called "Remove" which invokes a callback function. Here it is: (define (cb-remove x) ((lambda (name result) (cond [(number? result) (remove-name name…
Greenhorn
  • 411
  • 1
  • 6
  • 14
1
vote
1 answer

Backtracking infinite loop

This is Exercise 28.1.2 from HtDP. I've successfully implemented the neighbors function and all test cases pass. (define Graph (list (list 'A (list 'B 'E)) (list 'B (list 'E 'F)) (list 'C (list 'D)) …
Greenhorn
  • 411
  • 1
  • 6
  • 14
1
vote
2 answers

Idiomatic usage of filter, map, build-list and local functions in Racket/Scheme?

I'm working through Exercise 21.2.3 of HtDP on my own and was wondering if this is idiomatic usage of the various functions. This is what I have so far: (define-struct ir (name price)) (define list-of-toys (list (make-ir 'doll…
Greenhorn
  • 411
  • 1
  • 6
  • 14
1
vote
2 answers

Using an parameters as instanced within structure

I am currently completing chapter 7 of the htdp book and am trying to create an instance of the spider structure: #lang racket ;; spider-structure: structure -> ??? ;; defines a spider structure with two parameters: legs and volume (define-struct…
user3171116
  • 101
  • 1
  • 6
1
vote
1 answer

Why does my function sometimes return (shared ...) instead of (list ...)

I use the following function to turn a list of posns into a list of triples (posn, posn, symbol) for later use by draw-solid-line: (define (list->triples a-list) (cond [(= (length a-list) 1) empty] [else (cons (list…
Patrick Allo
  • 473
  • 4
  • 15
1
vote
1 answer

How am I supposed to create rows and columns of images?

First, I'm going through HtDP 2nd Edition and am using the BSL language pack. I'm currently on Exercise 131 and this is what it says: Exercise 131: Design two functions: col and row. The function col consumes a natural number n and an image i. It…
dotnetN00b
  • 5,021
  • 13
  • 62
  • 95
1
vote
2 answers

What is ws in the big-bang function really representing?

(big-bang ws (on-tick cth) (on-key keh) (on-mouse meh) ...) I know that the first parameter is a number and it's the described as the world state. But that just seems like vague terminology to me. Basically I…
dotnetN00b
  • 5,021
  • 13
  • 62
  • 95
0
votes
1 answer

Function definition and function call input seem coherent, but there's an error about the input when the application runs. What's wrong?

A novice in programming here (also first time posting here), trying to solve ex.91 from the htdp book (in racket - beginner student language). There's trouble with a helper function, which I named 'render-cat'. Here it is: ; Position -> Image ;…
0
votes
1 answer

Handling multiple possible return types in recursive function

I am using Racket ISL+ to write a recursion that is counting a series of structures. If the structures fails some parameters, I want to return a value of #false. However, at one point during recursion, I know the computer is getting 1 + 1 + 1 + 1 +…
0
votes
1 answer

Racket/Beginner Student Language Code Error

I am trying to animate a word letter by letter using Beginner Student Language on Racket. However, this code gives me an error "function call: expected a function after the open parenthesis, but found a part". I bolded the part that is giving me…
Atlecx
  • 1
0
votes
1 answer

HTDP2e Exercise 65 Write down the names of the functions (constructors, selectors, and predicates)

I took the following question from HTDP2e (exercise 65): Exercise 65. Take a look at the following structure type definitions: (define-struct movie [title producer year]) Write down the names of the functions (constructors, selectors, and…
Mr. Lisp
  • 3
  • 3
0
votes
1 answer

Racket BSL: How can I combine two instances of a structure in a list that have one common attribute?

I have a list of instances of a structure called "contact", which is basically a phone number and the duration a call with them took. I now want to add together all entries of the same phone number with the total duration of all calls with…
Another Noone
  • 11
  • 1
  • 5
0
votes
1 answer

Fixing "read-itunes-as-list: expects a file with XML document as first argument, given "itunes.xml"" for HTDP exercise 200

I'm doing the HtDP Exercises, and I'm having trouble on Exercise 200. I did what the book told me, but I kept on getting the same error. No matter what I tried, I always got this: read-itunes-as-list: expects a file with XML document as first…
fwoosh
  • 184
  • 3
  • 15
0
votes
1 answer

How to retrieve a button's label in Racket/PLT-Scheme?

I'm attempting Exercise 22.3.3 from HtDP but do not know how to retrieve the label of the button that was clicked. I get this message draw-message: expected as second argument, given: (instantiate (class ...) ...) which seems to suggest…
Greenhorn
  • 411
  • 1
  • 6
  • 14
0
votes
1 answer

Path or route function from HTDP not working

Following code from http://htdp.org/2003-09-26/Book/curriculum-Z-H-38.html#node_chap_30 does'nt seem to be working (I have added println statements for debugging) (define (neighbor a-node sg) (println "in neighbor fn") (cond [(empty? sg)…
rnso
  • 23,686
  • 25
  • 112
  • 234