Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxl!ihnp4!inuxc!pur-ee!uiucdcs!parsec!ctvax!pozsvath From: pozsvath@ctvax.UUCP Newsgroups: net.ai Subject: Re: Request for OPS5 examples - (nf) Message-ID: <6361@uiucdcs.UUCP> Date: Fri, 23-Mar-84 22:55:52 EST Article-I.D.: uiucdcs.6361 Posted: Fri Mar 23 22:55:52 1984 Date-Received: Sun, 25-Mar-84 12:44:03 EST Lines: 68 #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 { = 0}) --> (remove 1) (make factorial 1 1)) (p factn (fact { > 0}) --> (make fact (compute - 1))) ;;; Negative number entered. Quit (p factneg (fact { < 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 ) (fact ) --> (remove 2) (remove 1) (make factorial (compute ( + 1)) (compute ( * )))) ;;; When no more (fact k) statements are left, factorial k is fount ;;; (p factorial2 (factorial ) -(fact ) --> (write (crlf)) (write (compute - 1)) (write "!! =") (write ) (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 (accept)) (make fact )) ;;; 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!