Exam #2 Preparation: CS 405/505 Programming Languages, Exams of Programming Languages

An outline of the topics to be covered in exam #2 for the cs 405/505 programming languages course. The exam will consist of various question types, including fill in the blank, true or false, multiple choice, short answer, and discussion questions. Topics include programming languages semantics, functional programming languages, and logic programming. Students should have a solid understanding of denotational and axiomatic semantics, functional programming concepts, and prolog rule matching and list representation.

Typology: Exams

Pre 2010

Uploaded on 04/12/2010

koofers-user-6gh
koofers-user-6gh 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 405/505 PROGRAMMING LANGUAGES
TOPICS TO BE COVERED ON EXAM #2
November 6, 2007
The exam will cover everything we have discussed from Chapters 3 (i.e. Section 3.5), 15,
and 16 in the text and all notes, but emphasizing the material covered in class. The style of
the exam will be very flexible, possibly consisting of fill in the blank, true or false (possibly with
justification), multiple choice, matching, short answer (e.g. definitions or listing), and discussion
questions. You will not be asked to work detailed problems such as writing any actual code (i.e.
code in a specific language like Lisp or Prolog) You should have some ideas about the theory
behind implementation of programming languages (e.g. the relationship between formal models of
computation and programming languages, λ-calculus etc.). Some smaller problems such as drawing
a Lisp representation of a list, or tracing the execution of a Prolog program, are likely.
A brief outline of the topics we have covered is described below. (This list is intended to be
as complete as possible but may not be all inclusive.)
Programming Languages - Semantics. Of the three formal methods, operational, denotational
and axiomatic, we concentrated on denotational and axiomatic. You should know the goals
of formal semantics and should have specific ideas about how denotational semantics may
model interpretation of programs and how axiomatic semantics may be used to prove the
partial correctness of a program. You need not remember any specific denotational semantics
equations or axiomatic rules per se but should know enough about them to be able to explain
or use them if they are given to you. You should know the purpose and principles behind
axiomatic semantics but need not know the details of any axiomatic semantics rules.
Functional Programming Languages. Lambda calculus was introduced as the foundation of
denotational semantics and functional programming. The LISP, ML and Haskell program-
ming languages were discussed as examples of the functional language paradigm. You should
know the general design philosophy and syntactic and semantic flavor. You do NOT need to
know specific commands in detail, but should know some basic ones from LISP (e.g. defun,
cond,eq,setq,cons,car,cdr,append,list). Examples of the most detailed information
of a fundamental nature you should know would be how functions are defined, how lists are
represented internally, and how functions may be manipulated as data.
Logic Programming. You should know the general design philosophy and syntactic and se-
mantic flavor of Prolog. You do NOT need to know specific commands. Examples of the
most detailed information of a fundamental nature you should know would be how the rule
matching works (e.g. execution of rules, instantiation of variables, backtracking, etc.) and
the representation of lists.
pf3

Partial preview of the text

Download Exam #2 Preparation: CS 405/505 Programming Languages and more Exams Programming Languages in PDF only on Docsity!

CS 405/505 PROGRAMMING LANGUAGES

TOPICS TO BE COVERED ON EXAM

November 6, 2007

The exam will cover everything we have discussed from Chapters 3 (i.e. Section 3.5), 15, and 16 in the text and all notes, but emphasizing the material covered in class. The style of the exam will be very flexible, possibly consisting of fill in the blank, true or false (possibly with justification), multiple choice, matching, short answer (e.g. definitions or listing), and discussion questions. You will not be asked to work detailed problems such as writing any actual code (i.e. code in a specific language like Lisp or Prolog) You should have some ideas about the theory behind implementation of programming languages (e.g. the relationship between formal models of computation and programming languages, λ-calculus etc.). Some smaller problems such as drawing a Lisp representation of a list, or tracing the execution of a Prolog program, are likely.

A brief outline of the topics we have covered is described below. (This list is intended to be as complete as possible but may not be all inclusive.)

  • Programming Languages - Semantics. Of the three formal methods, operational, denotational and axiomatic, we concentrated on denotational and axiomatic. You should know the goals of formal semantics and should have specific ideas about how denotational semantics may model interpretation of programs and how axiomatic semantics may be used to prove the partial correctness of a program. You need not remember any specific denotational semantics equations or axiomatic rules per se but should know enough about them to be able to explain or use them if they are given to you. You should know the purpose and principles behind axiomatic semantics but need not know the details of any axiomatic semantics rules.
  • Functional Programming Languages. Lambda calculus was introduced as the foundation of denotational semantics and functional programming. The LISP, ML and Haskell program- ming languages were discussed as examples of the functional language paradigm. You should know the general design philosophy and syntactic and semantic flavor. You do NOT need to know specific commands in detail, but should know some basic ones from LISP (e.g. defun, cond, eq, setq, cons, car, cdr, append, list). Examples of the most detailed information of a fundamental nature you should know would be how functions are defined, how lists are represented internally, and how functions may be manipulated as data.
  • Logic Programming. You should know the general design philosophy and syntactic and se- mantic flavor of Prolog. You do NOT need to know specific commands. Examples of the most detailed information of a fundamental nature you should know would be how the rule matching works (e.g. execution of rules, instantiation of variables, backtracking, etc.) and the representation of lists.

CS 405/505 EXAM #2 SAMPLE QUESTIONS

  1. The mathematical model of computation that denotational semantics is based upon is called .
  2. A(n) is a condition which is true upon entry to a loop every time the loop is entered, and is still true at the termination of the loop.
  3. True or False. Denotational semantics is a method for defining the semantics of a programming language by giving an interpreter for that language.
  4. In pure λ-calculus, integers, Boolean values, lists, etc., must all be represented by λ-expressions. For example, 0 = λx.λy.y, 1 = λx.λy.x y, 2 = λx.λy.x (x y), etc., and succ = λz.λx.λy.x ((z x) y). succ is a function which adds 1 to its argument. Evaluate succ 1. Did you get 2? Why or why not?
  5. Consider the following Lisp function:

(defun update (store V n) (prog (currentenv newbinding newstore) (setq currentenv (cdaddr store))) (setq newbinding (cons (list ’eq ’V (list ’quote V)) (list n))) (setq newstore (list ’lambda (list ’V) (cons ’cond (cons newbinding currentenv)))) (return newstore))))

Note that the (prog (list of local variables) (exp-1) (exp-2) ... (exp-n) (return exp)) construction declares a list of local variables used in the expressions with exp being the value returned. Let S represent the Lisp expression (lambda (V) (cond ((eq V (quote x)) 4) (t (quote bottom)))). What is the internal list representation that Lisp uses for S? What is (cdaddr S)? Trace the execution of (update S ’x 5), showing the values of currentenv, newbinding, and newstore.

  1. Consider the Prolog program which solves the Towers of Hanoi problem. This problem is to move a stack of blocks from one location to another without ever changing the order in which blocks are placed on top of each other. A third stack may be used but only one block may be moved at a time.

hanoi(N) :- move(N, left, center, right).

move(0, X, Y, Z). move(N, X, Y, Z) :- N > 0, M is N - 1, move(M, X, Z, Y), display([X,Y]), move(M, Z, Y, X).

Trace the above program using the query hanoi(3). Show all queries which are generated by the execution and all moves which are printed. You may wish to draw a tree to show this clearly.