CSCI316 Assignment1-Lisp expression Solved

35.00 $

Category:

Description

5/5 - (2 votes)
  1. Write a Lisp expression that multiplies 30 by the result of 7 minus 2. To do this, you must write a call of the function * with two arguments; the second argument will be a call of the function – with two arguments.

 

2.[Exercise 1 on page 15 of Wilensky]  Write Lisp expressions to evaluate each of the following:

  • 32 + 42                           (b) 3*17 + 4*19                         (c) 123+13   (93+103)

 

3.(a) Write a Lisp expression that divides thirty by the result of seven minus three, in such a way that the result is a             rational number (i.e., 15/2).

  • Write a Lisp expression that divides thirty by the result of seven minus three, in such a way that the result is a

floating-point number (i.e., 7.5).  Do not use the FLOAT function.

 

4.[Exercise 3 on page 16 of Wilensky]  Write a Lisp expression that computes the mean of the five numbers eighty-three,      eighty-three, eighty-five, ninety-one, and ninety-seven.  Do this in such a way that the result is rational, and then in such a way      that the result is a floating-point number.  Do not use the FLOAT function.

 

  1. Lisp always prints rational numbers (fractions) in lowest terms; for example, if you enter the number 20/12 at Clisp’s  >       prompt (with no spaces before or after the “/”)  then Clisp will print the equivalent number  5/3.   Write a number that you      can enter at Clisp’s  >   prompt to determine whether or not the two integers 7,360,001,711 and 58,879,948,151 are relatively      prime.  If they are not relatively prime, then find their greatest common divisor.   (Two integers are said to be relatively prime      or coprime if no integer greater than 1 divides both of them.  For example, 20 and 9 are relatively prime; but 10 and 8 are not      relatively prime because 2 divides both 10 and 8.)

 

6.[Exercise 4 on p. 16 of Wilensky]  The Lisp function SQRT returns the non-negative square root of any non-negative real      argument.  Use this function to write two Lisp expressions that evaluate to the roots of the equation x2 – 11x – 1302 = 0.  In      other words, use SQRT to write two Lisp expressions that are respectively equivalent to the following:

 

(a)                                                                                             (b)                                                                              −(−11)+ (−11)×(−11)−4×1×(−1302)                                                  −(−11)− (−11)×(−11)−4×1×(−1302)

2×1                                                                           2×1

 

7.[Exercise 7 on p. 17 of Wilensky] Write a Lisp expression that can be entered at Clisp’s  >  prompt to determine the order in      which Common Lisp evaluates function arguments when it calls a function.   You may assume that the order is either      left-to-right or right-to-left, and that the same order is used in all Common Lisp function calls.   [Hint: Consider a function      call (–  <expr>1  <expr>2).   To  evaluate this call with left-to-right argument evaluation order, do the following: First, evaluate      <expr>1;  next, evaluate <expr>2; finally, subtract the second result (i.e., the value of <expr>2) from the first result (i.e., the      value of <expr>1).    To evaluate this call with right-to-left argument evaluation order, do the following: First, evaluate <expr>2;      next, evaluate <expr>1; finally, subtract the first result (i.e., the value of <expr>2) from the second result (i.e., the value of      <expr>1).   Normally, both evaluation orders would of course produce the same final value.  But if evaluation of one of the two      arguments has a side-effect, then evaluation order may make a difference.  Try to think of an expression (– <expr>1  <expr>2)       for which one of the argument evaluation orders would produce an error but the other would not.]

 

*If you wish to use Clisp on a Windows PC, download clisp-2.49-win32-mingw-big.zip by pointing a web browser to                             https://sourceforge.net/projects/clisp/files/clisp/2.49/clisp-2.49-win32-mingw-big.zip/download 

and unzip the zip archive to a folder. Then check that the folder contains a file named clisp.exe, and add the folder to your PATH––see,

e.g., https://www.architectryan.com/2018/03/17/add-to-the-path-on-windows-10/ if you don’t know how. After that you should be able to run    Clisp by opening a cmd or powershell window and then entering clisp.

 

Clisp is also available for a Mac: I used https://formulae.brew.sh/formula/clisp to install it on my Mac.

 Note: You are not required to install Clisp on your PC or Mac, and I cannot guarantee that you will be able to do so.

 

 

  • Assignment1-bsqf23.zip