Test your procedure by computing
(quadratic-root 1 -5 6)
(quadratic-root 2 -10 12)
(quadratic-root 1 4 4).
In each case, use algebra to check your answers.
What are (quadratic-root 1 0 1) and (quadratic-root 1 0
2)?
[Would these two examples work in other programming languages
that you know?]
(define semip
(lambda (x y z)
(/ (+ x y z) 2)))
(define solution1
(lambda (x y z)
(sqrt (* (semip x y z)
(- (semip x y z) x)
(- (semip x y z) y)
(- (semip x y z) z)))))
(define helper
(lambda (s x y z)
(sqrt (* s (- s x) (- s y) (- s z)))))
(define solution2
(lambda (x y z)
(helper (/ (+ x y z) 2) x y z)))
Often, it is convenient to move this window to the right the computer screen. This is accomplished by moving the mouse to the labeled bar emacs:... at the top of the XEmacs window. Press the left mouse button on this labeled bar, and move the mouse (keeping the left button depressed). The XEmacs window will follow your mouse movements. When the XEmacs window is where you want it, release the left mouse button.
While XEmacs is an extremely powerful editor, many common capabilities are highlighted with buttons and menus at the top of window. These menus are analogous to most word processing packages, and thus are not discussed here. Ask the instructor as questions arise. (If something particularly strange seems to be happening, type <Ctrl/g> to stop the processing of a command.)
Type the following Scheme definitions into the XEmacs file.
(define pi 3.141596535)
(define q 'quarts)
(define a (sqrt 2))
As you are typing, note that when you type a right parenthesis,
XEmacs shows you which left parenthesis it matches. This will be
particularly helpful when typing longer Scheme programs. Save the file by clicking on the save button at the top of the XEmacs window. XEmacs then will open a new window, asking you to give a file name for the program. For example, to save your work in a file first-test.ss, you could type this name into the new file-naming window and hit the return key. File first-test.ss now is ready for use within Scheme.
Move the mouse to the dtterm window and type scheme to begin running the Scheme environment. Within Scheme, you can use the definitions from a file with the load procedure. Here, you should type
(load "first-test.ss")
More generally, load allows you to specify any file by placing the
file name in double quotes.Check that the definitions from the file work as expected by typing
pi
q
a
Modify first-test.ss so that it contains a typographical error. (Remember to save the file by clicking on the save button.) What happens when you try to load this version of the file into scheme?
(+ 2 3)
in the file and load it into scheme. Describe what happens.
(define r (+ 2 3))
(define s '(+ 2 3))
(define t (quote (+ 2 3)))
(define u ''(+ 2 3))
(define v (quote (quote (+ 2 3))))
Load the revised file into Scheme and check the definitions for r, s, t, u,
and v. Explain the results that you observe.
submit first.session
[This indicates that what follows will be recorded in a file called
first.session.]
cat first-test.ss
print first.session
This document is available on the World Wide Web as
http://www.math.grin.edu/~walker/courses/153/lab-procedures.html