Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- object Solution {
- /**
- * Implement a "clock" object.
- * The object must have a single field, and three methods:
- * - The field should contain a number which is initially 0.
- * - The "tick" method should increment the number by 1.
- * - The "reset" method should reset the clock to 0.
- * - The "read" method should return the current clock value.
- */
- val clock =
- """
- (object
- ((field cnt 0))
- (
- (method tick () (set cnt (+ 1 cnt)))
- (method reset () (set cnt 0))
- (method read () cnt)
- (method tick-x-times (x) (set cnt (+ x cnt)))
- ))
- """
- /**
- * Implement a "clock factory" object.
- * The clock factory object must have a single field, and two methods:
- * - The field should contain a number which is initially 0. The value of this field decides
- * what the initial value is for the clocks that the factory produces. (See the test
- * template for examples.)
- * - The "set-init" method updates the field of the clock factory (and hence the initial value
- * of produced clocks).
- * - The "produce" method returns a "clock" object (where a "clock" object is as defined above).
- */
- val clockFactory =
- s"""
- (object
- ((field init-val 0))
- (
- (method set-init (new-init-val) (set init-val new-init-val))
- (method produce () (let ((cl $clock)) (msg cl tick-x-times init-val)))
- ))
- """
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement