Skip to content

Commit

Permalink
document in all relevant places that delaying syntax error in check e…
Browse files Browse the repository at this point in the history
…xpressions is intentional and provide an example of why this is so
  • Loading branch information
mfelleisen committed Sep 17, 2024
1 parent 87820a2 commit 1dea4eb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
9 changes: 6 additions & 3 deletions htdp-doc/scribblings/htdp-langs/prim-ops.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@
[(check-expect expression expected-expression)]]{

Checks that the first @racket[expression] evaluates to the same value as the
@racket[expected-expression].
@racket[expected-expression].

@;%
@(begin
Expand All @@ -341,8 +341,11 @@ A @racket[check-expect] expression must be placed at the top-level of a
ahead of the tested function definition. By placing @racket[check-expect]s
there, a programmer conveys to a future reader the intention behind the
program with working examples, thus making it often superfluous to read
the function definition proper.

the function definition proper. Syntax errors in
@racket[check-expect] (and all check forms)
are intentionally delayed to run time so that students can write tests
@emph{without} necessarily writing complete function headers.

It is an error for @racket[expr] or @racket[expected-expr] to produce an
inexact number or a function value. As for inexact numbers, it is
@italic{morally} wrong to compare them for plain equality. Instead one
Expand Down
4 changes: 3 additions & 1 deletion htdp-doc/test-engine/test-engine.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ as parameters to configure the behavior of test reports.
Each check form may only occur at the top-level; results are collected
and reported by the test function. Note that the check forms only
register checks to be performed. The checks are actually run by the
@racket[test] function.
@racket[test] function. Furthermore, syntax errors in check forms
are intentionally delayed to run time so that students can write tests
@emph{without} necessarily writing complete function headers.

@defform[(check-expect expr expected-expr)]{
Checks whether the value of the @racket[expr] expression is
Expand Down
6 changes: 5 additions & 1 deletion htdp-lib/test-engine/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ teaching languages.
- `test-engine.rkt`: register tests, run them, collect & inspect results
- `racket-tests.rkt`: surface syntax for the teaching languages
- `syntax.rkt`: utilities for defining surface syntax in a way that
works with the stepper
works with the stepper
- `markup-gui.rkt`: graphical rendering for markup in a `text%` object
- `test-markup.rkt`: convert test results into markup
- `srcloc.rkt`: extract source location from the stack trace in an exception
Expand All @@ -32,3 +32,7 @@ the `simple-tree-text-markup` package.

The teaching languages use `test-engine/markup-gui` to render in
DrRacket.

Note The test engine delays the reporting of error in `syntax.rkt` so
that check expressions can be used without always writing a dummy
function header. See note there.
15 changes: 14 additions & 1 deletion htdp-lib/test-engine/syntax.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,20 @@
(syntax-column stx)
(syntax-position stx)
(syntax-span stx)))))
(define test-expr-checked-for-syntax-error #`(convert-compile-time-error #,test-expr))

;; -----------------------------------------------------------------------------
;; We want to delay compile-time errors in the check position of
#; (check-expect check expect)
;; to the run-time phase so that students are encourgaed to run
;; partial programs and get feedback on some of the tests. The
;; "exemplar" package (Shriram, Daniel Patterson, Ben Lerner and
;; Northwestern?) relies on this property in that it requests that
;; students formulate tests WITHOUT even formulating a function header.

(define test-expr-checked-for-syntax-error
#`(convert-compile-time-error #,test-expr))
;; -----------------------------------------------------------------------------

(if (eq? 'module (syntax-local-context))
#`(define #,bogus-name
#,(stepper-syntax-property
Expand Down

1 comment on commit 1dea4eb

@shhyou
Copy link
Collaborator

@shhyou shhyou commented on 1dea4eb Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to running partial programs, background expansion also requires delayed compile-time errors.

Please sign in to comment.