![]() |
![]() |
|
home—lectures—exams—hws—breeze (snow day)
Due Nov.16 (Fri) in class.
I suggest, by Monday, having completed test-cases for N3,
and at least two of the prolog queries.
Submit:
a hardcopy with the prolog queries for this file,
and just the additional tests for N3
and just the function(s) that changed between N2 and N3.
We continue to build on the language implementation started in hw07. You can implement this homework in either Java or Racket. Please indicate in your submitted file, what sections of code are udpated and what is unchanged from hw07/hw07-soln. You don't need to turn in any hardcopy of unchanged-code (but submit a fully-working copy in the drop-box).
Write the following Prolog predicates.
Do not use
Note that xsb Prolog contains several list functions which you are NOT to use for this assignment
(e.g.
As ever, your program should follow good style, including appropriate white space, meaningful variable names, and as well as a header comment with your name, the name of the assignment, etc.. (You can have comments describing how a predicate works if you want; however, you can also assume your program is being read by somebody who understands the fundamentals of Prolog.)
N3 is just like N2, except we now
allow one variable to shadow another.
For example, we might have a
Thus, when substituting,
only substitute “free occurrences” of an
(5pts)
Fill in the following blanks:
Re-indent
the following two N3 expressions so that
each
let x = 5 in (let x = (x plus 1) in (x plus 2);); let y = let z = 4 in (let y = 99 in z;); in (let z = 5 in ((let z = 10 in y;) plus (y plus z));); |
You can put all your answers in comments near the top of your main file (N3.rkt or Expr.java), and in the hardcopy code-excerpts.
(5pts)
Make the necessary changes to N2
to enable shadowing.
(You are encouraged to build on your solution,
but you can also use the posted N2 solutions.)
The change should be quite small;
you'll submit your entire running project on D2L, but
a hardcopy that only has the function(s) you change.
Be sure to indicate (for Java) which class contains the changed function.
Here are some examples of the list predicates, for the second prolog question:
last([1,2,3], 3). Yes last([1,2,3], 4). No last([1,2,3], Y). Y=3 last([], Y). No last(Y, 3). Y=[3]. nextToLast([1,2,3], 2). Yes nextToLast([1,2,3], 3). No nextToLast([1,2,3], Y). Y=2 nextToLast([1], Y). No nextToLast(Y, 3). Y=[3, _h114], % does not have to be 114, 'course. Y=[_h116, 3, _h114]. lastTwoReversed([1,2,3], Y). Y=[3,2] lastTwoReversed([1], Y). No reverseLastTwo([1,2,3,4], Y). Y=[1,2,4,3] reverseLastTwo([1,2], Y). Y=[2,1] reverseLastTwo([1], Y). No
The interpreter project is based on the first chapters of Programming Languages and Interpretation, by Shriram Krishnamurthi. As a result, this homework assignment is covered by the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States License. Although we're using a different dialect of racket than that book, you might find it helpful to skim it.
1
nor any “binding occurrences”:
The first
home—lectures—exams—hws—breeze (snow day)
©2012, Ian Barland, Radford University Last modified 2012.Nov.28 (Wed) |
Please mail any suggestions (incl. typos, broken links) to ibarland ![]() |
![]() |