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
4
votes
1 answer

New to programming, question about exercise in Prologue of HTDP

This may be a silly question but I'm completely new to programming. I'm towards the bottom of the Prologue in "How to Design Programs" (2nd ed) and there are 4 changes that you are challenged to make to the "Rocket Landing" program in DrRacket. I'm…
Asif Kazmi
  • 43
  • 4
4
votes
4 answers

Can this be turned into a tail recursive function?

Going through HtDP and came across a problem which was: Design the function multiply. It consumes a natural number n and multiplies it with some arbitrary number x without using *. This is what I came up with: (define (multiply n x) (cond [(=…
dotnetN00b
  • 5,021
  • 13
  • 62
  • 95
4
votes
1 answer

How To Change Image Sizes in Racket

I am making a game using racket and need a background bitmap image. But the image I have selected is too big. How do I change the size? What I have: (bitmap/url "http://www.example.com/")
Darth Bobo
  • 43
  • 7
3
votes
2 answers

How does HtDW correlate with HtDP?

So there's a companion PDF to How to Design Programs (HtDP) called How to Design Worlds (HtDW). And I'm wondering how much of HtDP do I have to read/know to be able to start reading HtDW? Are the chapters from the two books correlated in any way?
dotnetN00b
  • 5,021
  • 13
  • 62
  • 95
3
votes
1 answer

Idiomatic usage of local vs lambda?

In Exercise 30.1.1 of HtDP, I started off using local and then modified it to use lambda in order to answer the question. (define (add-to-each2 accu a-list) (cond [(empty? a-list) empty] [else (local ((define s (+ accu (first a-list)))) …
Greenhorn
  • 411
  • 1
  • 6
  • 14
2
votes
2 answers

How can I use read-csv-file to read from a string instead?

The 2htdp/batch-io library contains the useful read-csv-file procedure for reading a CSV file into a list. It takes a filename as its argument. Unfortunately, it does not take a string containing CSV as its argument. Suppose I have a CSV in a string…
Flux
  • 9,805
  • 5
  • 46
  • 92
2
votes
1 answer

make-posn returns # instead of posn

I am trying to get a feel for the draw library in Scheme, but I've already had a problem. (define defaultpos (make-posn 400 400)) (start 800 800) (draw-circle defaultpos 10 'green) In theory, this should open up a new window with a green circle in…
2
votes
1 answer

Processing 2 lists simultaneously using append

I'm stuck on the question for Exercise 17.1.2 from HTDP. This is what I've got so far: (define (cross alist1 alist2) (cond [(empty? alist1) empty] [else (append (list (first alist1)(first alist2)) (cons (first…
Greenhorn
  • 411
  • 1
  • 6
  • 14
2
votes
1 answer

What is the error in the following racket code?

;creating traffic signal image (require 2htdp/image) (define (bulb c) (circle 10 "solid" c)) (above (bulb "red") (bulb "yellow") (bulb "green")) The Error Displayed is:. Module Language: there can only be one expression in the…
rajdeep04
  • 17
  • 5
2
votes
2 answers

about racket : #lang not enabled

I've got to learn how-to-design-program for a while.But once I started to use my Emacs to learn htdp, I met some problem. THE PROBLEM IS THAT: I typed #lang racket , but it just show: > stdin::7: read: #lang not enabled in the current context …
Arthas Dark
  • 21
  • 1
  • 2
2
votes
1 answer

Why return empty and not the list itself?

Chapter 4, HtDP. Note: I've seen this in other questions as well. Is it for a clarity reason or an algorithmic reason, that I am unaware of, that the base case returns empty instead of the list itself which is empty. Example: ; List-of-numbers ->…
dotnetN00b
  • 5,021
  • 13
  • 62
  • 95
2
votes
2 answers

Racket Emacs mode for mimicking Scribble or HTDP sample code examples?

I really like the syntax highlighting and coloring of the code samples throughout How to Design Programs. For example: http://www.htdp.org/2003-09-26/Book/curriculum-Z-H-9.html#node_sec_6.5 Does anyone have something like this as a jumping off…
Scott Klarenbach
  • 37,171
  • 15
  • 62
  • 91
1
vote
1 answer

How to use RackUnit to check for an error?

I have the following Racket code. #lang racket (require rackunit racket/exn) (define (string-last s) (let ((lng (string-length s))) (substring s (- lng 1) lng))) (string-last "") (check-equal? (string-last "1") "1") (check-equal?…
bobeff
  • 3,543
  • 3
  • 34
  • 62
1
vote
1 answer

Query in the topic "List"

It would be a great help if someone could please tell this question: Write a function sqr-list that consumes a list of numbers and produces a list of the squares of those numbers, computed using the built-in sqr function. Write the function by…
1
vote
1 answer

How do I start defining map from fold?

I'm working through Htdp 2e, and have been given the problem of defining the map function from foldr or foldl. I'm not sure where to start. Map takes in a function of one argument and a list. So I have defined my function similarly. Fold requires a…
Seiferxiii
  • 13
  • 4