Skip to content

Instantly share code, notes, and snippets.

@FernandoBasso
Last active October 15, 2021 22:43
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FernandoBasso/c3f772fff707af3cd2c592e60af77529 to your computer and use it in GitHub Desktop.
Save FernandoBasso/c3f772fff707af3cd2c592e60af77529 to your computer and use it in GitHub Desktop.
Just to show some stuff that DrRacket inserts (when using htdp/bsl) and that is probably why some things were not working in emacs/geiser/repl.
#lang htdp/bsl
;; #reader(lib "htdp-beginner-reader.ss" "lang")((modname area-tests) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f () #f)))
;; Given length of one side of square, produce the area of the square.
(check-expect (area-of-square 3) 3) ;; This test is wrong.
(check-expect (area-of-square 3.2) (* 3.2 3.2))
(define (area-of-square side)
(* side side))
;; When you test this, the first test will fail. The function is correct, but the
;; test is expecting that the area of a square with side 3 is 3, which is incorrect;
;; 9 would be the area of such a square.
;;
;; If you change the function to conform to the test, you'll end up with a function
;; that produces incorrect values.

How to use htpd/bsl from emacs or command line

To run tests like those with check-expect, your .rkt file must start with:

#lang htdp/bsl

or

#reader(lib "htdp-beginner-reader.ss" "lang")((modname area-tests) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f () #f)))

But not both.

Then, from racket-mode, do C-c C-t (racket-test) and be happy. From the command line,

raco test file.rkt

Thanks to @lexi-lambda in #racket. He refused to change his nick to lexi-λ as I suggested, though.

@aaronhooper
Copy link

aaronhooper commented Apr 4, 2020

Thanks for this!

#lang syntax for HTDP seems to have no record on the Racket docs, so to include intermediate and advanced:

#lang htdp/bsl
#lang htdp/bsl+
#lang htdp/isl
#lang htdp/isl+
#lang htdp/asl

@FernandoBasso
Copy link
Author

Thanks for the full list! Much appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment