{"size": 2071, "ext": "scrbl", "max_stars_repo_path": "htdp-doc/teachpack/htdp/scribblings/convert.scrbl", "max_stars_repo_name": "bdeket/htdp", "max_stars_repo_stars_event_min_datetime": "2015-01-14T20:28:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T04:04:26.000Z", "max_issues_repo_path": "htdp-doc/teachpack/htdp/scribblings/convert.scrbl", "max_issues_repo_name": "bdeket/htdp", "max_issues_repo_issues_event_min_datetime": "2015-01-14T19:50:21.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-19T21:38:00.000Z", "max_forks_repo_path": "htdp-doc/teachpack/htdp/scribblings/convert.scrbl", "max_forks_repo_name": "bdeket/htdp", "max_forks_repo_forks_event_min_datetime": "2015-01-14T19:11:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T05:11:39.000Z"}
{"max_stars_count": 85, "max_issues_count": 132, "max_forks_count": 81, "avg_line_length": 40.6078431373, "max_line_length": 96, "alphanum_fraction": 0.7619507484}
#lang scribble/doc

@(require scribble/manual "shared.rkt"
          (for-label racket teachpack/htdp/convert))

@teachpack["convert"]{Converting Temperatures}

@;declare-exporting[teachpack/htdp/convert]
@defmodule[#:require-form beginner-require htdp/convert]

The teachpack @racket[convert.rkt] provides three functions for
converting Fahrenheit temperatures to Celsius. It is useful for a single
exercise in HtDP. Its purpose is to demonstrate the independence of
``form'' (user interface) and ``function'' (also known as ``model'').

@defproc[(convert-gui [convert (-> number? number?)]) true]{Consumes a
conversion function from Fahrenheit to Celsius and creates a graphical user
interface with two rulers, which users can use to convert temperatures
according to the given temperature conversion function.}

@defproc[(convert-repl [convert (-> number? number?)]) true]{Consumes a
conversion function from Fahrenheit to Celsius and then starts a
read-evaluate-print loop. The loop prompts users to enter a number and then
converts the number according to the given temperature conversion function.
A user can exit the loop by entering ``x.''}

@defproc[(convert-file [in string?][convert (-> number? number?)][out string?]) true]{Consumes a
file name @racket[in], a
conversion function from Fahrenheit to Celsius, and a string
@racket[out]. The program then reads all the number from
@racket[in], converts them according to @racket[convert], and prints the
results to the newly created file @racket[out].

@bold{Warning}: If @racket[out] already exists, it is deleted.}

Example: Create a file with name @racket["in.dat"] with some numbers in
it, using your favorite text editor on your computer.  Define a function
@racket[f2c] in the Definitions window and set teachpack to
@filepath{convert.rkt} and click Run.  Then evaluate
@(begin
#reader scribble/comment-reader
(racketblock
 (convert-gui f2c)
 ;; and 
 (convert-file "in.dat" f2c "out.dat")
 ;; and 
 (convert-repl f2c)
))
Finally inspect the file @racket["out.dat"] and use the repl to check the
answers. 
