Factor Exercises

Author: Zackery L. Arnold

CPS 499-03: Emerging Languages, Spring 2017

1. Define a word caesar in a vocabulary homework that takes a string of alphabetical characters and an integer and applies the integer to each character in the string. Your solution must handle both positive and negative offset values. Only include uppercase and lowercase alphabetical characters in the output. For example, ABCD with an offset of 4 should produce EFGH. Factor your solution into a primary word caesar and set any helper words as private. This problem can be solved in less than 10 lines of code.

Examples:
```> "SEESPOTRUN" 26 caesar .
"seespotrun"

> "SEESPOTRUN" -26 caesar .
"seespotrun"

> "ABCDEFG" 7 caesar .
"HIJKLMN"
```
2. Define a new tuple class novel that represents a fictional literary work. Include member variables that correspond to the novel's title, author, genre, publisher, year of publication, and an identification number. Use strings for the first four variables and integers for the last pair. Include a constructor that takes values for each variable as arguments and sets them automatically. Also include a word book-print that takes a novel as an argument and prints the novel's details in the following simple format:
```Class: Novel
Title: < title >
Author: < author >
Genre: < genre >
Publisher: < publisher >
Year: < year >
ID: < number >
```
Examples:
```> "Narnia" "C. S. Lewis" "Fantasy" "Harper-Collins" 1952 1

--- Data stack:
T{ novel f "The Lion, the Witch, and the Wardrobe" "C. S. Lewis" "Fantasy" "Geoffrey Bles" 1950...

> book-print
Class: Novel
Title: The Lion, the Witch, and the Wardrobe
Author: C. S. Lewis
Genre: Fantasy
Publisher: Geoffrey Bles
Year: 1950
ID: 1
```
3. Extend the solution to problem 2 to two new classes of books - textbook and article. For textbooks, change the 'genre' field to 'subject'. For article, change the 'genre' field to 'discipline' and add 'journal' and 'volume' fields. Then, with the three classes, define a mixin class called library that will represent the union of different types of books. Adjust the book-print word from before to be generic with templates for each type of book. Publish the library and each class in a library vocabulary.

Examples:
```> USE: library
> "The C Programming Language" "Ritchie, D. and Kernighan, B." "Computer Science" "Prentice Hall" 1988 2

--- Data stack:
T{ textbook f "The C Programming Language"...

> book-print
Class: Novel
Title: The C Programming Language
Author: Ritchie, D. and Kernighan, B.
Subject: Computer Science
Publisher: Prentice Hall
Year: 1988
ID: 2

> "Factor: A Dynamic Stack-based Programming Language" "Pestov, S." "Computer Science" "ACM SIGPLAN Notices" 45 "ACM Press" 2010 3

--- Data stack:
T{ article f...

> book-print
Class: Novel
Title: Factor: A Dynamic Stack-based Programming Language
Author: Pestov, S.
Discipline: Computer Science
Journal: ACM SIGPLAN Notices
Volume: 45
Publisher: ACM Press
Year: 2010
ID: 3
```