benson@dcdwest.UUCP (03/05/84)
I am learning ops5 using the Forgy manual. It is tough going and I find the manual a little obscure. I have received a few example programs from other people, but I sure would like some more. If you have a good example OPS5 program, could you mail it to me. Thanks in advance, Peter Benson decvax!ittvax!dcdwest!benson ucbvax!sdcsvax!dcdwest!benson
pozsvath@ctvax.UUCP (03/24/84)
#R:dcdwest:-10800:ctvax:45200002:000:1807
ctvax!pozsvath Mar 22 21:52:00 1984
;;; /
;;; Peter Ozsvath
;;;
;;; Factorial Program in OPS-5
;;; Simulates the stack in working memory
;;;
;;; Stage 1. Fill the working memory with (fact 1) (fact 2)...(fact n)
;;;
(p fact0 (fact {<x> = 0}) --> (remove 1) (make factorial 1 1))
(p factn (fact {<n> > 0}) --> (make fact (compute <n> - 1)))
;;; Negative number entered. Quit
(p factneg (fact {<n> < 0}) -->
(write "Good-bye."))
;;; Stage 2. Sweep out the unnecessary (fact k) and (factorial k (k-1)!)
;;; and add new (factorial (k+1) k!
;;;
(p factorial (factorial <x> <y>) (fact <x>) -->
(remove 2)
(remove 1)
(make factorial (compute (<x> + 1)) (compute (<x> * <y>))))
;;; When no more (fact k) statements are left, factorial k is fount
;;;
(p factorial2 (factorial <x> <y>) -(fact <x>) -->
(write (crlf))
(write (compute <x> - 1))
(write "!! =")
(write <y>)
(write (crlf))
(make infinifact))
;;; Called once at the beginning
;;;
(p pretty_fact (start) -->
(write "Program to demonstrate the power, compactness, and robustness")
(write (crlf))
(write "of the Winning OPS 5. This program inputs numbers whose")
(write (crlf))
(write "factorials - lo and behold - it computes RECURSIVELY")
(write (crlf))
(write (crlf))
(remove 1)
(make infinifact))
;;; Circular "loop" that reads in numbers
;;;
(p infinifact (infinifact) -->
(remove 1)
(write "Enter a positive number to compute its factorial,")
(write (crlf))
(write "or a negative one to quit")
(write (crlf))
(bind <x> (accept))
(make fact <x>))
;;; Start
(start ((start)))
This program computes factorials in OPS-5. Some things seem to be
rather difficult to do in OPS-5. This same program could be
written in several lines of lisp!