Assignment 2

Practice with Rigal

Goals

To learn the basics of Rigal, especially the list and tree data types and pattern parameters.

Procedure

Read through the material on Rigal at:

 

http://www.cs.nmsu.edu/~rth/cs/cs471/RigalNotes.html

http://www.ida.liu.se/%7Evaden/rigal/langdesc.html

http://www.cs.nmsu.edu/~rth/cs/cs471/Rigal_Slides.pdf

 

then answer these questions:

 

  1. Write the Rigal form for a list with three items, an atom ‘Atom’, a number 3456 and a list consisting of the numbers 7, 8 and the atom ‘X’.
  2. Write the Rigal form for a list with one item, the empty list.
  3. Write the Rigal form for a tree with two branches, labeled ‘one’ and ‘two’ with leaves 1 and 2, respectively.
  4. Write the Rigal form for a tree with one branch, labeled ‘one’ which has a subtree which has two branches, labeled ‘one’ and ‘two’ with leaves ‘A’ and ‘B’ .
  5. Write a Rigal rule that will accept three arguments, the first must be the atom ‘XXX’, the second can be any number and the third can be a list of exactly one element which can be any identifer atom (e.g. ‘anyId’, ‘A’, ‘XXX’, etc.). The code in the rule should just print out the three arguments passed in.
  6. Write a Rigal rule which will print out any list (top-level only, not sublists) in reverse order. It should work with your answers to questions 1 and 2.
  7. Write a Rigal rule which will print out all the leaves of any tree. It should work with your trees in questions 3 and 4.

Grading

  1. 2 points
  2. 2 points
  3. 2 points
  4. 3 points
  5. 3 points
  6. 4 points
  7. 4 points

 (total 20 points)

Hints

The first 4 questions test your understanding of the constant forms for the list and tree data types. Question 5 uses patterm parameters and the inbuilt rules for numbers and identifers (or the defaults in the syntax of variables). Question 6 uses the iterative list pattern, list operations and the list constructor form. Question 7 uses the iterative tree pattern, recursion and alternative parameter sets.

Due Date

January 31st. by 5:00pm.