CS 330 Home Schedule Resources

Assignment 15

Seeing past syntax;
Relational Programming

Estimated time: 3 hours

In this assignment, there are two parts. First, you will have the opportunity to familiarize yourself with some of the syntax of two languages you may not have used before. Syntactic differences can be a psychological barrier to using a new language, even though the differences may be only superficial. The goal of this assignment is to help you PRACTICE overcoming this barrier and recognize similar underlying semantics. Another goal is to expose you to some influential families of language syntax that you probably haven't seen before.

In the second part, you will practice writing a relational program that uses first-class search spaces.

Exercises

  1. Secret Messages. Suppose a friend regularly sends you messages in a simple code, and you wish to write a little program to decode them automatically. The code consists of reversing the order of characters in the true message and then padding each character of the true message with completely arbitrary characters, one on either side, making a triplet. For example, the message "CS 330" could be encoded in Oz-style notation as "[[r 0 w] [3 3 s] [c 3 p] [r s s] [a c e]]". Write a decoder program in two languages: Python and Scheme. Use each decoder to decipher this message:
    [[a r e][w e e][o w l][b o o][a p p][i s l][q i z][g e l][e g g][o d d][f e e][a l l][h w o][n o t][t n t][c k a]]
    (Feel free to translate it to a more convenient syntax in each language.)

    These languages are available on the lab machines, and can be started by typing the name of the language at the command prompt. Ie., 'python', or 'drscheme'. For python, this will put you in an interactive read-eval-print loop where you can directly type program fragments and execute them. For scheme, a graphical interface will start up. The top pane is a text editor, and clicking on the 'Run' bottom will execute all fragments in the buffer. The bottom buffer is a read-eval-print loop, and also will show the results of running the top buffer.

    Here are links to some helpful resources: Python, Scheme

  2. Relational programming. Write a relational program to find an assignment to eight variables named A...H. The program should ensure that the assignment meets the folowing two constraints. How large is the search space?
    1. The domain of each variable is an integer in the range 1-8.
    2. A< B< C< D< E< F< G< H

  3. Feedback.