1. Define a LISP function MIN-2 with the following properties. MIN-2 takes two arguments, A and B. If the arguments A and B are numbers such that ASB, then MIN-2 returns A. If A and B are numbers such that A > B, then MIN-2 returns B. If A or B is not a number, then MIN-2 returns the symbol ERROR. Examples: (MIN-2 21.5 7/2) =- 7/2 (MIN-2 17.5 29) =- 17.5 (MIN-2 5 'APPLE)= ERROR (MIN-2 '(31) '(54)) =► ERROR LISP Assignment 3: Page 1 of 3 2.[Exercise 4 on p. 72 of Wilensky] Write a LISP function SAFE-AVG that takes 2 arguments and returns the average of those arguments if they are numbers. If one or both of the arguments is not a number, the function should return NIL. Examples: (SAFE-AVG 23 47.4) = 35.2 (SAFE-AVG 3 8) 11/2 (SAFE-AVG 'ORANGE PLUM) NIL (SAFE-AVG '(23.1) 47.3) NIL

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
icon
Concept explainers
Question
5. Questions about the problems that are e-mailed to me will not be answered before the submission deadline.
6. In this document the term list should be understood to mean proper list.
1. Define a LISP function MIN-2 with the following properties. MIN-2 takes two arguments,
A and B. If the arguments A and B are numbers such that A<B, then MIN-2 returns A. If A
and B are numbers such that A>B, then MIN-2 returns B. If A or B is not a number, then
MIN-2 returns the symbol ERROR
Examples: (MIN-2 21.3 7/2) => 7/2
(MIN-2 17.5 29) = 17.5
(MIN-2 (31) (54) => ERROR
(MIN-2 5 'APPLE) => ERROR
LISP Assignment 3: Page 1 of 3
2.[Exercise 4 on p. 72 of Wilensky] Write a LISP function SAFE-AVG that takes 2 arguments
and returns the average of those arguments if they are numbers. If one or both of the arguments
is not a number, the function should return NIL.
Examples: (SAFE-AVG 23 47.4) => 35.2
(SAFE-AVG 3 8) = 11/2
(SAFE-AVG 'ORÁNGE PLUM) => NIL
(SAFE-AVG (23.1) 47.3) => NIL
3.[Exercise 2 on p. 72 of Wilensky] Write a LISP predicate ODD-GT-MILLION that takes one
argument, and which returns T if its argument is an odd integer greater than a million, but returns
NIL otherwise. Hint: Make use of the predicate INTEGERP.
Examples:
(ODD-GT-MILLION 92010231) => T (ODD-GT-MILLION 17) => NIL (ODD-GT-MILLION 92010232) => NIL
(ODD-GT-MILLION 21/5) => NIL
(ODD-GT-MILLION (2010231)) = NIL
(ODD-GT-MILLION 1718671.24) = NIL
(ODD-GT-MILLION 'APPLE) = NIL
4.[Exercise 3 on p. 72 of Wilensky] Re-read the discussion of MEMBER in sec. 6.6 of Touretzky
or on p. 51 of Winston & Hom. Then write a LISP predicate MULTIPLE-MEMBER that takes
two arguments and behaves as follows: If the first argument is a symbol or number and the
second is a list, then MULTIPLE-MEMBER returns a true value if the first argument occurs at
least twice in the second argument, and returns NIL otherwise.
Transcribed Image Text:5. Questions about the problems that are e-mailed to me will not be answered before the submission deadline. 6. In this document the term list should be understood to mean proper list. 1. Define a LISP function MIN-2 with the following properties. MIN-2 takes two arguments, A and B. If the arguments A and B are numbers such that A<B, then MIN-2 returns A. If A and B are numbers such that A>B, then MIN-2 returns B. If A or B is not a number, then MIN-2 returns the symbol ERROR Examples: (MIN-2 21.3 7/2) => 7/2 (MIN-2 17.5 29) = 17.5 (MIN-2 (31) (54) => ERROR (MIN-2 5 'APPLE) => ERROR LISP Assignment 3: Page 1 of 3 2.[Exercise 4 on p. 72 of Wilensky] Write a LISP function SAFE-AVG that takes 2 arguments and returns the average of those arguments if they are numbers. If one or both of the arguments is not a number, the function should return NIL. Examples: (SAFE-AVG 23 47.4) => 35.2 (SAFE-AVG 3 8) = 11/2 (SAFE-AVG 'ORÁNGE PLUM) => NIL (SAFE-AVG (23.1) 47.3) => NIL 3.[Exercise 2 on p. 72 of Wilensky] Write a LISP predicate ODD-GT-MILLION that takes one argument, and which returns T if its argument is an odd integer greater than a million, but returns NIL otherwise. Hint: Make use of the predicate INTEGERP. Examples: (ODD-GT-MILLION 92010231) => T (ODD-GT-MILLION 17) => NIL (ODD-GT-MILLION 92010232) => NIL (ODD-GT-MILLION 21/5) => NIL (ODD-GT-MILLION (2010231)) = NIL (ODD-GT-MILLION 1718671.24) = NIL (ODD-GT-MILLION 'APPLE) = NIL 4.[Exercise 3 on p. 72 of Wilensky] Re-read the discussion of MEMBER in sec. 6.6 of Touretzky or on p. 51 of Winston & Hom. Then write a LISP predicate MULTIPLE-MEMBER that takes two arguments and behaves as follows: If the first argument is a symbol or number and the second is a list, then MULTIPLE-MEMBER returns a true value if the first argument occurs at least twice in the second argument, and returns NIL otherwise.
4.[Exercise 3 on p. 72 of Wilensky] Re-read the discussion of MEMBER in sec. 6.6 of Touretzky
or on p. 51 of Winston & Horn. Then write a LISP predicate MULTIPLE-MEMBER that takes
two arguments and behaves as follows: If the first argument is a symbol or number and the
second is a list, then MULTIPLE-MEMBER returns a true value if the first argument occurs at
least twice in the second argument, and returns NIL otherwise.
Examples: (MULTIPLE-MEMBER 'A '(B A BBACA D)) => (A CA D)
(MULTIPLE-MEMBER 'A '(B ABBCCA D)) => (A D)
(MULTIPLE-MEMBER 'A '(B A BBC D)) =- NIL
Notice that the behavior of MULTIPLE-MEMBER is unspecified in cases where the first
argument is not a symbol or number, and in cases where the second argument is not a list. Your
definition may therefore return any value or produce an evaluation error in such cases.]
5. Define a LISP function MONTH->INTEGER which takes as argument a symbol that should be the
name of a month, and which returns the number of the month. For example:
(MONTH->INTEGER 'MARCH) => 3
If the argument is not a symbol that is the name of a month, the function should return the symbol
ERROR For example:
(MONTH-> INTEGER 'C) => ERROR
(MONTH->INTEGER 'QUOTE)=>ERROR (MONTH->INTEGER '(MAY))=>ERROR
(MONTH->INTEGER 'JUNE) => 6
(MONTH->INTEGER 7) => ERROR
6. Define a LISP function SCORE->GRADE which takes a single argument, s, and returns a symbol
according to the following scheme:
s2 90
87 ss< 90
83 <s< 87
80 <s< 83
77<s< 80
A
73 ss< 77
70 <s<73
60 <s< 70
C+
А-
C
B+
D
B
s< 60
F
B-
If the arguments is not a number then the function should return NIL.
Examples: (SCORE->GRADE 86.3) = B+ (SCORE->GRADE 106) => A (SCORE->GRADE -10.1) =F
(SCORE->GRADE 59.9) => F (SCORE->GRADE 83) => B+ (SCORE->GRADE 74) => C+
(SCORE->GRADE 67) = D
(SCORE->GRADE (86.3)) => NIL (SCORE->GRADE DOG) => NIL
(SCORE->GRADE 87.0) => A-
Transcribed Image Text:4.[Exercise 3 on p. 72 of Wilensky] Re-read the discussion of MEMBER in sec. 6.6 of Touretzky or on p. 51 of Winston & Horn. Then write a LISP predicate MULTIPLE-MEMBER that takes two arguments and behaves as follows: If the first argument is a symbol or number and the second is a list, then MULTIPLE-MEMBER returns a true value if the first argument occurs at least twice in the second argument, and returns NIL otherwise. Examples: (MULTIPLE-MEMBER 'A '(B A BBACA D)) => (A CA D) (MULTIPLE-MEMBER 'A '(B ABBCCA D)) => (A D) (MULTIPLE-MEMBER 'A '(B A BBC D)) =- NIL Notice that the behavior of MULTIPLE-MEMBER is unspecified in cases where the first argument is not a symbol or number, and in cases where the second argument is not a list. Your definition may therefore return any value or produce an evaluation error in such cases.] 5. Define a LISP function MONTH->INTEGER which takes as argument a symbol that should be the name of a month, and which returns the number of the month. For example: (MONTH->INTEGER 'MARCH) => 3 If the argument is not a symbol that is the name of a month, the function should return the symbol ERROR For example: (MONTH-> INTEGER 'C) => ERROR (MONTH->INTEGER 'QUOTE)=>ERROR (MONTH->INTEGER '(MAY))=>ERROR (MONTH->INTEGER 'JUNE) => 6 (MONTH->INTEGER 7) => ERROR 6. Define a LISP function SCORE->GRADE which takes a single argument, s, and returns a symbol according to the following scheme: s2 90 87 ss< 90 83 <s< 87 80 <s< 83 77<s< 80 A 73 ss< 77 70 <s<73 60 <s< 70 C+ А- C B+ D B s< 60 F B- If the arguments is not a number then the function should return NIL. Examples: (SCORE->GRADE 86.3) = B+ (SCORE->GRADE 106) => A (SCORE->GRADE -10.1) =F (SCORE->GRADE 59.9) => F (SCORE->GRADE 83) => B+ (SCORE->GRADE 74) => C+ (SCORE->GRADE 67) = D (SCORE->GRADE (86.3)) => NIL (SCORE->GRADE DOG) => NIL (SCORE->GRADE 87.0) => A-
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Types of Linked List
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education