CSCE 330 Fall 2007 Quiz 17: ML Statements and Functions, Quizzes of Computer Science

Information about quiz 17 for the csce 330 fall 2007 course, which covers ml (metalanguage) statements and functions. Students are required to determine if a given ml statement is an expression or a command, and whether it will result in an exception. Additionally, they are asked to write an ml function that adds 1 to all elements of a non-empty integer list using patterns.

Typology: Quizzes

Pre 2010

Uploaded on 09/02/2009

koofers-user-b1g
koofers-user-b1g 🇺🇸

5

(1)

9 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSCE 330 Fall 2007
Quiz 17
Assigned Thursday, 07-11-29
1. if 5 < 6 orelse (5 div 0) < 6 then 7 else 8;
(a) Is the above ML statement an expression or a command? (Choose
one). Answer: an expression
(b) Will the above ML statement result in an exception? Answer: no
(c) If not, what will the result be? Answer: 7
2. Write an ML function that adds 1 to all the elements of a non-empty
integer list. Call the function ad1xs. Use patterns.
Answer:
fun ad1xs [x] = [x+1]
| ad1xs (x::xs) = (x+1) :: ad1xs (xs);
1

Partial preview of the text

Download CSCE 330 Fall 2007 Quiz 17: ML Statements and Functions and more Quizzes Computer Science in PDF only on Docsity!

CSCE 330 Fall 2007

Quiz 17

Assigned Thursday, 07-11-

  1. if 5 < 6 orelse (5 div 0) < 6 then 7 else 8;

(a) Is the above ML statement an expression or a command? (Choose one). Answer: an expression (b) Will the above ML statement result in an exception? Answer: no (c) If not, what will the result be? Answer: 7

  1. Write an ML function that adds 1 to all the elements of a non-empty integer list. Call the function ad1xs. Use patterns. Answer:

fun ad1xs [x] = [x+1] | ad1xs (x::xs) = (x+1) :: ad1xs (xs);