Docsity

SML Programming Concepts and Functions, Exams of Business Administration

Toggle sidebar
bg1
CIS 505 Exam 1 Notes Questions and Answers 2025
How do signify a real in SML?
12.0, 3e~2, 3,14e12
How do you signify a character in SML?
#"x", #"A", #\n"
How do you concatenate two strings in SML?
Using the ^ operator
i.e. "abra" ^ "cadabra" = "abracadabra"
What operators can you not use on reals?
=, <>
Can < and > be used on strings?
Yes, and it means lexicographically precedes. It returns a bool
i.e. "a" < "b", "abc" < "acb"
What are the 3 boolean operators?
not, andalso, orelse
SML has what two types of typing?
Static and Strong
How to cast as a real in SML?
real(11) = 11.0
How to round down, round up, round generally, and truncate?
floor(5.4) = 5
ceiling(5.4) = 6
round(5.5) = 6
trunc(~5.4) = ~5
How to go from character to int? Vice-versa?
ord(#"0") = 48
chr(48) = #"0"
What is a tuple?
A fixed-size ordered collection of two or more values. Always same length, sometimes different types
pf3
pf4

Partial preview of the text

Download SML Programming Concepts and Functions and more Exams Business Administration in PDF only on Docsity!

CIS 505 Exam 1 Notes Questions and Answers 2025

How do signify a real in SML? 12.0, 3e~2, 3,14e How do you signify a character in SML? #"x", #"A", #\n" How do you concatenate two strings in SML? Using the ^ operator i.e. "abra" ^ "cadabra" = "abracadabra" What operators can you not use on reals? =, <> Can < and > be used on strings? Yes, and it means lexicographically precedes. It returns a bool i.e. "a" < "b", "abc" < "acb" What are the 3 boolean operators? not, andalso, orelse SML has what two types of typing? Static and Strong How to cast as a real in SML? real(11) = 11. How to round down, round up, round generally, and truncate? floor(5.4) = 5 ceiling(5.4) = 6 round(5.5) = 6 trunc(~5.4) = ~ How to go from character to int? Vice-versa? ord(#"0") = 48 chr(48) = #"0" What is a tuple? A fixed-size ordered collection of two or more values. Always same length, sometimes different types

Ex: (1, "a", true) (4, (1,"a",true)) What is a list? A list is a list of all the same type. Always same type, sometimes different length What are the return types of these list operations? Empty List [] Head hd Tail tl Append @ cons :: 'a list 'a list→'a 'a list→'a list 'a list'a list→'a list 'a'a list→'a list What do explode and implode to? Explode takes a string and converts it into a list of characters Implode takes a list of characters and makes it a string Fill in the blanks: SML is a(n) __________________-based (________________) language with ___________, ____________ typing SML is an expression-based(functional) language with strong, static typing. Write a basic function that takes in a number and adds one fun inc(x) = x+1; What does tl return? All the elements of the list except the first one Write a function that uses the a function and a number as its parameters. It is supposed to add the number and one to the function fun do_fun(f,x) = f(x) + x + 1; val a = 2; val a = 2 : int fun myfun x = x + a; val myfun = fn : int - > int val a = 4

('a - > bool) - > 'a list - > 'a list What is the type of foldr and foldl? ('a*'b - > 'b) - > 'b - > 'a list - > 'b What does member do? member is a function that checks to see if a number is in a list What is the type of member? ''a list - > ''a - > bool What does intersection do? Intersections checks through a list to see if a number in that list exists in the second list and returns a new list full of the interesecting numbers What is the type of intersection and union? ''a list * ''a list - > ''a list What does union do? Union checks to see what numbers are not in the two lists and then returns a list of those numbers What is the type of remove_dups? ''a list - > ''a list How do you create your own type? datatype of (name here) = (Type) of (int, string, etc.) | (Type) of (int, string,etc.) Ex: datatype of card = Club of int | Diamond of int | Heart of int | Spade of int

  • Heart 7; val it = Heart 7 : card