4.2. ARITHMETIC EXPRESSIONS IN SCHEME
49
; hypotenuse34.servlet    this returns the length
; of the hypotenuse of a right triangle who other sides
; have length 3 and 4
(sqrt (+ (* 3 3) (* 4 4)))
This servlet contains a more complex scheme expression with four operators (two
multiplication operators  * , one addition  + , and one square root  sqrt ).
The Scheme server evaluates such an expression by first evaluating the innermost
expressions (* 3 3) and (* 4 4) to get 9 and 16 respectively. These values
are subsituted back into the expression to yield the simpler expression:
(sqrt (+ 9 16))
Next the sum is evaluated to yield 25 which is substituted back into the expres 
sion to get:
(sqrt 25)
which evaluates to
5.0
and this is sent back to the browser.
Scheme provides a large set of arithmetic operators including the following
(+ a b ... c) addition
(  a b) subtraction
(* a b ... c) multiplication
(/ a b) division
(sqrt a) square root
(exp a) exponential function
(log a) natural logarithm
(sin a) sine (in radians)
(cos a) cosine (in radians)
(tan a) tangent (in radians)
(asin a) arcsin
(acos a) arccosine
(atan a) arctangent
(round a) rounds to the nearest integer
(expt a b) raise a to the b power
Exercise 2 What is the result of evaluating the following Scheme expressions:
(* 1 2 3 4 5)
(+ 5 (* 3 (+ 6 (* 7 2))))
(+ (* 1 1) (* 2 2) (* 3 3) (* 4 4) (* 5 5))




  

Home

About Services Network Support FAQ Order Contact
 

Tomcat Web Hosting

Our partners:Jsp Web Hosting Unlimited Web Hosting Cheapest Web Hosting  Java Web Hosting Web Templates Best Web Templates PHP Mysql Web Hosting Interland Web Hosting Cheap Web Hosting PHP Web Hosting Tomcat Web Hosting Quality Web Hosting Best Web Hosting  Mac Web Hosting 

Lunarwebhost.net  Business web hosting division of Vision Web Hosting Inc. All rights reserved