1
0
mirror of https://github.com/PDP-10/its.git synced 2026-01-18 17:16:59 +00:00
PDP-10.its/src/ellen/script.intro
2018-07-16 07:04:57 -07:00

562 lines
24 KiB
Common Lisp
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

;;; -*- Mode:LISP; Package:MACSYMA -*-
; ** (c) Copyright 1981 Massachusetts Institute of Technology **
(SETQ $LOADPRINT NIL)
;This shouldn't be needed any more --kmp
;(COND ((STATUS FEATURE MACLISP) (LOAD '((LISP)DEFMAX))))
(DEFUN IF MACRO (X)
(COND ((NULL (CDDDR X)) `(COND (,(CADR X) ,(CADDR X))))
(T `(COND (,(CADR X) ,(CADDR X)) (T . ,(CDDDR X))))))
(DEFSCRIPT $CONSOLEPRIMER
"Welcome to the MACSYMA Primer. This section of the Primer
is called the CONSOLEPRIMER because it is intended to be
used by people who have not had previous experience
interacting with a computer console."
(COND ((AND $PAGEPAUSE CURSORPOS)(SCRIPT 'CRTCONSOLE NIL)))
(SLEEP 2)
"You will notice that your console looks much like a typewriter, except
for having a few special keys. The two most important special
keys are the 'altmode' and the 'control' key. The 'altmode'
may be labeled 'alt', 'esc', '(sel)', or 'escape'. The 'control'
key may be labeled 'CTRL' or 'CNTL'. The altmode is used to
enter the MACSYMA editor. Do not attempt to use the editor while
you are in the Primer since it may tend to confuse you. A future
script will deal with editing. The control key is used in
the same fashion as the shift key on the typwriter, i.e. you hold
it down and type the character whose 'control' value you wish.
For example, to type control-Z, you would hold down the control
key and type a Z. Don't do that now, as control-Z is the control
character that will return you to top level when you are ready
to log out."
(SLEEP 2)
"The Primer will explain some of the aspects of MACSYMA to you and allow
you to try out various examples. Your responses to
the Primer must end with a semi-colon (;). That is the one
thing which the Primer cannot correct you on, since it will not
even see your response until you have typed the semi-colon. Thus
if nothing seems to be happening, check that you have typed the
semi-colon."
"In the Primer you should answer all questions the system asks. There
are three kinds of questions:"
"1. Questions you can answer with a yes or a no. You type the word
YES or the word NO followed immediately by a semi-colon (;) to
answer these. Case does not matter, upper or lower will do.
Try it here: Type YES; or NO;"
(IF (YESORNO) (TERPRI))
"2. Questions which require you to select a script or an option. The system
will print out a list, for example:"
(MENU '($SIMPLIFICATION $SCRATCHPAD $ASSIGNMENT))
"This list is called the 'menu', the list of scripts available.
You select a script to see by typing the number of your choice
followed by a semi-colon (;), to answer these. E.g."
"3;"
"Now you try it."
(MENU '($SIMPLIFICATION $SCRATCHPAD $ASSIGNMENT))
(NUMCHK 3)
"3. Requests to type in commands to MACSYMA. The system will make a
request, such as 'Type in a polynomial in X,' and then give you
a dummy MACSYMA command line number. You then type the command,
followed by a semi-colon. This is to give you a chance to practice
what you are learning. If you type the command correctly, the
system will pass what you type to MACSYMA, and MACSYMA will
evaluate it and return a response. If you make a mistake the
system will attempt to tell you what you did wrong, and will
offer you a chance to try again. Here, try typing X+2;"
(INCHK '((MPLUS) $X 2))
"The response, as you see, is just the expression itself, since
no simplification or operation was necessary or specified."
"Do you know how to type 'control-characters'?"
(IF (NOT (YESORNO)) (SCRIPT 'CTRLCHAR NIL))
"Control-G is the QUIT command for MACSYMA."
"The other control characters you should know about for MACSYMA are:"
"Control-L: this reprints the command line you are typing. On a display
console it will also clear the screen. It is particularly useful
if you have used rubout (delete) a lot and want to verify that you
have everything right."
"Control-^: this will put you into LISP, the language MACSYMA is written in.
You will not usually want to use it, but should know about it so
you can avoid typing it. If you do type it by mistake, control-G
will get you back to a MACSYMA command line."
"Control-A: this enters a MACSYMA break. This suspends the current
computation, and allows you to 'poke around' in your MACSYMA,
perhaps to open a file for output, or to see what the value of
some variable is. To get out of the 'break' and resume the
computation, type 'exit;'"
"Control-]: this prints out the time used by the computation so far.
You can type it at any point during a computation. Try it now to
see how much CPU time this PRIMER session has used:"
(SLEEP 8)
"Now you are ready to move along to the Introductory Script of the Primer."
(COND ((EQ 'WSMR (STATUS UNAME))(SCRIPT '$INTRO NIL))
(T (SEEN (STATUS UNAME) '$CONSOLEPRIMER)))
(SCRIPT '$INTRO NIL))
(DEFSCRIPT $INTRO
"Welcome to the MACSYMA Primer. This is the script called INTRO."
"Please terminate responses to all questions with a semi-colon (;).
You may delete any characters you have typed by using
the delete or rub-out key on your console. The deleted
character will be erased if you are using a display terminal.
If you are using a printing terminal, it will be
typed back so you know what has been deleted."
"If you do not understand how to type an expression, or have tried
several times and wish to give up, you may type NO; and the
PRIMER will show you the correct way to do it."
"In this PRIMER session, after an optional introduction to
MACSYMA syntax, a few of the specialized MACSYMA commands
will be introduced. After that we will discuss some of the
facilities of MACSYMA which allow you to manipulate algebraic
expressions within the computer in much the same way you
do on paper."
"MACSYMA is a system for symbolic algebraic manipulation.
It uses a syntax resembling ALGOL 60."
"Do you need help with MACSYMA syntax?"
(IF (YESORNO) (SCRIPT '$SYNTAX NIL))
"MACSYMA contains a large set of commands for manipulating
algebraic expressions. Among these are commands to
factor, expand, differentiate, integrate, substitute and
simplify. Lets try an example:"
"Type in"
(DISPLA EXAMPLE1)
(INCHKP 'CHKEXONEP)
"Now you may want this expression multiplied out. The EXPAND command
will do this for you. It takes one argument, the expression
to be EXPANDed. You may refer to an expression you have typed
in already by using its D-line label. Type:"
(PCLINE `(($EXPAND) ,DLABEL))
(CMDCHKP `(($EXPAND) ,DLABEL))
"On the other hand, factored form is smaller, and the FACTOR command
in MACSYMA will factor expressions for you. There is a short
hand for the D-line label of the last expression
you typed, the character %. Type"
(PCLINE '(($FACTOR) $%))
(CMDCHKP `(($FACTOR) ,DLABEL))
"The MACSYMA commands to integrate and differentiate (INTEGRATE and
DIFF) both take a second argument -- the variable to integrate
or differentiate with respect to. The second argument is
separated from the first by a comma. For example,"
(PCLINE `(($INTEGRATE) ,DLABEL $X))
"If you would type in the expression for"
(DISPLA EXAMPLE2)
"Then we can try integrating and differentiating it."
(INCHK EXAMPLE2)
"Now use the INTEGRATE command to integrate the last expression"
(setq $LOADPRINT T)
(INCHK `(($INTEGRATE) ,DLABEL $X))
"Now use the DIFF command to differentiate your last result."
(INCHK `(($DIFF) ,DLABEL $X))
"You may note that the answer MACSYMA just computed is not the same as
the original expression before it was integrated and
differentiated. The terms are not expanded, nor is the sum
put over a common denominator. The RATSIMP (RATional
SIMPlification) command will do this for you."
(CMDCHKP `(($RATSIMP) ,DLABEL))
"Would you like to learn in more detail about MACSYMA's simplification
commands?"
(IF (YESORNO) (SCRIPT '$SIMPLIFICATION NIL))
"MACSYMA has facilities to handle various series expansions, for
example, Taylor Series. The TAYLOR command takes four
arguments, an expression, a variable, the point around which
to expand the expression, and the power through which to
generate the terms. To generate a TAYLOR series of the
square root of 1+X, around the point 0, to the 5th power,
type:"
"TAYLOR (SQRT(1+X),X,0,5)"
(INCHK '(($TAYLOR) ((%SQRT) ((MPLUS) 1 $X)) $X 0 5))
"You can manipulate these expressions just like any others.
For instance, you can multiply the previous expression by
itself. Type:"
"%*%"
(INCHK `((MTIMES) ,DLABEL ,DLABEL))
"The TAYLOR command converts an expression internally
to MACSYMA's Canonical Rational Expression (CRE) form by
expanding it and combining all terms over a common denominator.
This simplifies the operation of the command.
Expressions that are in CRE form always have the symbol /R/
following the line label. The RATSIMP command also converts
expressions internally into CRE form, but converts them back
to the usual general form at the end.
Type in:"
(DISPLA '((MEXPT) ((MPLUS) $X 3) 20))
(INCHK '((MEXPT) ((MPLUS) $X 3) 20))
"RATSIMP takes one argument, the expression to be converted.
Use RATSIMP on the expression you just typed in."
(CMDCHKP `(($RATSIMP) ,DLABEL))
"This form is obviously bulkier than our original expression,
but the expanded CRE form is useful in many problems."
"Now, differentiate this expression with respect to X"
(INCHK `(($DIFF) ,DLABEL $X))
"If you use FACTOR on this expression, you will see that indeed it
is the appropriate derivative."
(CMDCHKP `(($FACTOR) ,DLABEL))
"MACSYMA has a facility to solve equations using the SOLVE command, which
usually takes two arguments, the first an expression, and the second
the variable to be solved for. The second argument may be
omitted if the expression contains only one variable.
Use SOLVE on the following expression:"
(DISPLA '((MPLUS) ((MEXPT) $X 6) ((MMINUS) 1)))
(INCHK '(($SOLVE) ((MPLUS) ((MEXPT) $X 6) ((MMINUS) 1))))
"What would you like to go over now?"
(PRIMER-SELECT '($SIMPLIFICATION $SCRATCHPAD $ASSIGNMENT $SYNTAX $EXIT)) )
(DEFSCRIPT $SIMPLIFICATION
"This is the SIMPLIFICATION script."
"MACSYMA has several functions to help simplify expressions. Each
one of them has special properties which make it useful in
certain situations."
"For dealing with ratios of polynomials, there are two
functions which are of use. These are RATSIMP and
RATEXPAND. RATSIMP rationally simplifies an expression
and all of its subexpressions and returns a quotient of
two polynomials. RATEXPAND is similar
to EXPAND but the result is a sum of terms each of the form A
over B with all terms over the least common denominator."
"Type in a polynomial in X."
(INCHKP 'POLYCHK)
"Now use the RATSIMP command on it."
(CMDCHKP `(($RATSIMP) ,DLABEL))
"Sometimes before using RATSIMP on a complicated expression, it is useful
to cancel common factors and combine terms a bit, to allow RATSIMP
to work more efficiently."
"To illustrate this let's make MACSYMA print out the time it uses, by
setting SHOWTIME to TRUE."
(MACSYMA '((MSETQ) $SHOWTIME $TRUE))
"Now type in this expression:"
(DISPLA SIMPEXAMPLE1)
(INCHK SIMPEXAMPLE1)(SETQ D DLABEL)
"And now use RATSIMP on it."
(CMDCHKP `(($RATSIMP) ,DLABEL))
"That works, but for larger expressions it might take quite a long time, or
might run out of space. XTHRU is a command that will do some
preliminary simplification like cancelling common factors and
combining terms. Like RATSIMP, it takes one argument, the
expression to be operated on.
So referring back to the original expression
by its D-label, @D use XTHRU to simplify it."
(GC)
(CMDCHKP `(($XTHRU) ,D))
"Now use RATSIMP on it."
(CMDCHKP `(($RATSIMP) ,DLABEL))
"As you can see, the total time for the XTHRU and RATSIMP are considerably
less than that for just the RATSIMP of the original expression."
"Now, we will turn off the TIME printout again, by setting TIME to FALSE."
(MACSYMA '((MSETQ) $SHOWTIME $FALSE))
"Along with FACTOR, EXPAND, RATSIMP, and RATEXPAND,
MACSYMA also has a simplifier to handle expressions
involving logs, exponentials, and radicals. This
simplifier is called RADCAN, which is short for radical
canonical. RADCAN can take a long time to simplify
some expressions, so it should be used with this in mind."
"Would you like to try RADCAN on an expression?"
(IF (YESORNO) (SCRIPT 'TRYRADCAN NIL))
"Would you like to learn more about simplifying and manipulating
expressions?"
(IF (YESORNO) (SCRIPT '$SCRATCHPAD NIL))
"What would you like to go over now?"
(PRIMER-SELECT '($INTRO $SCRATCHPAD $ASSIGNMENT $SYNTAX $EXIT)) )
(DEFSCRIPT $SCRATCHPAD
"This is the SCRATCHPAD script."
"In some cases the user
will want to have access to a finer level of control over
his expressions. MACSYMA has commands which allow the
user to play with his expressions in the machine in much
the same way he would with paper and pencil."
"One important command of this type in MACSYMA is the SUBST
command. This command can be used to replace all
occurrences of a subexpression with some other expression
in an intermediate result. This is useful, for
example, in expressions involving trigonometric
functions, where the MACSYMA simplifiers are not willing,
for reasons of efficiency, to try all possible trigonometric
identities."
"SUBST(A,B,C) means substitute A for B in C. The
resulting expression will be mathematically equivalent to the
original expression if A is mathematically equivalent to B."
(SLEEP 2)
"Here is a simple example of the use of SUBST. The
numerator of this expression is equal to 1 for all X,
but the MACSYMA simplifiers will not simplify it directly."
(MACSYMA SUBST-EXAMPLE1)
"There are three ways to use SUBST on this example:"
"One could substitute 1 for SIN(X)^2+COS(X)^2"
"One could substitute 1-SIN(X)^2 for COS(X)^2"
"Or one could substitute 1-COS(X)^2 for SIN(X)^2"
"The first way is more direct, but in more complex
examples where the sin squared plus cos squared is deeply
entwined with other elements of the expression the second
or third way would be necessary. Pick the way you like
best and simplify the expression by using SUBST."
(INCHKP 'SUBEXAMPLE1)
"SUBST however, can only substitute for expressions
that constitute an extractable part of the larger expression they
are contained in. In the case where the thing that you
want to substitute for is embedded in the expression,
then a more powerful tool is needed. RATSUBST is a
command that can be helpful in these cases. Here is an
example of the same simplification as before but with it
embedded so that the COS(X)^2 is not easily extractable from
the expression."
(MACSYMA SUBST-EXAMPLE2)
"Now use RATSUBST to simplify the above."
(INCHKP 'SUBEXAMPLE2)
"In working with algebraic expressions by hand, one will
often take part of a larger expression and work with that for
a time. In MACSYMA that can by done by using the PART
command. The PART command takes two or more arguments.
The first is the expression and the rest are specifications
as to which part is to be taken. Each of the specifications
is an integer that tells which one of the top level operators
arguments to take. Consider this example:"
(MACSYMA EXAMPLE3)
"This is a quotient of sums and thus the quotient is the top
level operator. Its first argument is its numerator, and its
second argument is the denominator. Thus:"
(PCLINE `(($PART) ,DLABEL 1))
"would return the numerator. If PART had been given a third
argument it would pick one of the terms of the numerator. Now
use the PART command to get the R from the above expression."
(SETQ $PARTSWITCH T)
(PARTCHK '$PART '$R)
(SETQ $PARTSWITCH NIL)
"What would you like to go over now?"
(PRIMER-SELECT '($INTRO $SIMPLIFICATION $ASSIGNMENT $SYNTAX $EXIT)) )
(DEFSCRIPT $SYNTAX
"This is the SYNTAX script."
"Input to MACSYMA is done with a syntax somewhat like that of
Fortran or Algol. All input lines are terminated
with a semi-colon (;). Input lines
are labeled consecutively starting with (C1), and then
(C2) (C3) etc. MACSYMA results are labeled from
(D1) on. Thus (D1) is the result of the computations
performed by MACSYMA on the user's input string (C1)."
"These line numbers may be used to refer to expressions."
(SLEEP 2)
"The display MACSYMA prints out is two dimensional, like a textbook.
You must be careful not to let this confuse you. If you want
to type in the mathematical expression 2X, which of course is
'2 times X', you must type '2*X' even though MACSYMA will
print back"
(DISPLA '((MTIMES) 2 $X))
"Try typing in 2X or some other expression times X:"
(SYNCHK '(MTIMES) '((MTIMES) 2 $X))
"* is the multiplication operator. The other operators MACSYMA
uses are:"
~! for Factorial,~
~^ or ** for Exponentiation,~
~* for Multiplication,~
~. for non-commutative multiplication~
~/ for Division, ~
~+ for Addition, and~
~- for Subtraction.~
(SLEEP 2)
"These operators are applied following the traditional rules for
operator precedence.
Do you know what is meant by operator precedence?"
(IF (NOT (YESORNO)) (SCRIPT 'PRECEDENCE NIL))
"Variables in MACSYMA (and names of functions and arrays) consist of
a string of numbers and letters including the character %. Other
characters may be included by preceding them with a backslash
(\). Variable names are not limited in length, but must not
begin with a number."
"Constants are either numbers or one of the special constants, pi, e
(the base of natural logarithms), or i (the square root of minus
one) which are written %PI, %E, and %I to distinguish them from
the variables pi, e, and i."
(SLEEP 2)
"An operator may appear before its argument(s), between its arguments
or after its argument. Operators that appear before their
arguments are usually functions (such as SIN and COS) or
MACSYMA commands (such as INTEGRATE or RATSIMP). The arguments
to these operators are enclosed in parentheses, for example"
(PCLINE '((%SIN) 3.141))
"or"
(PCLINE '(($INTEGRATE) $% $X))
"Would you like to practice typing in some expressions?"
(IF (YESORNO) (SCRIPT 'PRACTICE NIL))
"That's all for syntax.")
(DEFSCRIPT PRACTICE
"Let's start with a simple linear expression: type in the expression for"
(DISPLA PRAC-EXAMPLE1)
(INCHK PRAC-EXAMPLE1)
"Okay, now try one where you need to use some parentheses to get the proper
operator precedence"
(DISPLA PRAC-EXAMPLE2)
(INCHK PRAC-EXAMPLE2)
"Now try a ratio."
(DISPLA PRAC-EXAMPLE3)
(INCHK PRAC-EXAMPLE3)
"Okay, try another type of exponentiation"
(DISPLA PRAC-EXAMPLE4)
(INCHK PRAC-EXAMPLE4)
"Here's a polynomial"
(DISPLA PRAC-EXAMPLE5)
(INCHK PRAC-EXAMPLE5)
"Now try a slightly more complicated ratio:"
(DISPLA PRAC-EXAMPLE6)
(INCHK PRAC-EXAMPLE6)
"Would you like to continue with the Introductory Section of
the primer?"
(IF (NOT (YESORNO)) (SCRIPT '$HELP2 NIL)))
(DEFSCRIPT $HELP2
"What would you like to go over? "
(PRIMER-SELECT '($CONSOLEPRIMER $INTRO $SIMPLIFICATION $SCRATCHPAD $SYNTAX $ASSIGNMENT $EXIT)) )
(DEFSCRIPT PRECEDENCE
"MACSYMA uses the conventional mathematical operator precedence."
"Would you like to see some examples of how MACSYMA represents
operator precedence?"
(IF (YESORNO) (SCRIPT 'PRECEDENCE1 NIL)))
(DEFSCRIPT PRECEDENCE1
"Uparrow, ^, for exponentiation, has higher precedence that * for
multiplication, so:"
(MACSYMA '((MTIMES) ((MEXPT) $A 2) $B))
"Asterisk, *, for multiplication has higher precedence than + for
addition, so:"
(MACSYMA '((MPLUS) $A ((MTIMES) $B $C)))
"Parentheses may be used to change the order of application of
operators,"
(MACSYMA '((MTIMES) ((MPLUS) $A $B) $C))
"If you need further examples, consult page 8 of the MACSYMA Manual."
(SLEEP 7))
(DEFSCRIPT TRYRADCAN
"Type in this expression:"
(DISPLA RADCANEXAMPLE)
(INCHKP 'CHKRADCAN)
"Now use RADCAN on it."
(CMDCHKP `(($RADCAN) ,DLABEL)))
(DEFSCRIPT $HELP
"Hello. Please terminate your responses with a ;.
What would you like to go over? (Select the number of the script you
would like to see.)
INTRO is a general introduction
for people who have never used MACSYMA or this PRIMER before."
(PRIMER-SELECT '($CONSOLEPRIMER $INTRO $SIMPLIFICATION $SCRATCHPAD $SYNTAX $ASSIGNMENT $EXIT)) )
(DEFSCRIPT CRTCONSOLE
"Since you have a display (CRT) console, there is one special
thing you must know before we proceed: When the printout
reaches the bottom of your screen, the system will print
**MORE**, --More Display?--, or --Pause--, and the output
will pause, leaving you as much time as you like to read
what has been printed. When you are ready to continue, you
hit the space bar once. The system will print --Continued--
and output will resume." )
(DEFSCRIPT CTRLCHAR
(SSTATUS TTYINT 7 'NIL)
"To type a control-character you use the key on your console labeled
'CTRL' or 'Control' in the same fashion as you would use the
'shift' key, that is you hold down the key labeled 'CTRL' and
strike the key you want to make a control-character. The
control-character which you will probably find the most useful
in MACSYMA, is control-G.
This is MACSYMA's 'QUIT' character, that is the character which
will cause MACSYMA to stop what it is doing and accept more input
from you. It is sort of the 'panic button', and will stop infinite
loops. So you can find it and practice
typing it, it is temporarily disabled as a 'QUIT' character."
"Try typing it now:"
(QUITCHK)
(SSTATUS TTYINT 7 'MQUIT))
(SETQ EXAMPLE1 '((MEXPT) ((MPLUS) $X 1) 3))
(SETQ EXAMPLE2 '((MQUOTIENT) $A
((MPLUS) ((MEXPT) $X 3) ((MTIMES) 2 ((MEXPT) $X 2)) $X)))
(SETQ EXAMPLE3 '((MQUOTIENT) ((MPLUS) $A $B $C) ((MPLUS) $Q $R $S)))
(SETQ EXAMPLE4 '(($FACTOR)
((MPLUS) ((MEXPT) $X 3)
((MTIMES) ((MEXPT) $X 2)
((MEXPT) $Y 2))
((MMINUS) ((MTIMES) $X ((MEXPT) $Z 2)))
((MMINUS) ((MTIMES) ((MEXPT) $Y 2)
((MEXPT) $Z 2))))))
(SETQ SUBST-EXAMPLE1 '((MQUOTIENT)
((MPLUS) ((MEXPT) ((%SIN) $X) 2)
((MEXPT) ((%COS) $X) 2))
((MPLUS) ((MEXPT) $X 2) 39)))
(SETQ SUBST-EXAMPLE2 '((MPLUS)
((MTIMES) ((MEXPT) ((%COS) $X) 3) ((%SIN) $X))
((MTIMES) ((%COS) $X) ((MEXPT) ((%SIN) $X) 3))))
(SETQ PRAC-EXAMPLE1 '((MPLUS)((MTIMES) 3 $X) 1))
(SETQ PRAC-EXAMPLE2 '((MEXPT)((MPLUS) $X 2) 3))
(SETQ PRAC-EXAMPLE3 '((MQUOTIENT) 1 ((%SIN) $X)))
(SETQ PRAC-EXAMPLE4 '((MEXPT) $%E ((MTIMES) 2 $%PI $I)))
(SETQ PRAC-EXAMPLE5 '((MPLUS)((MEXPT) $X 2)((MTIMES) 2 $X) 1))
(SETQ PRAC-EXAMPLE6 '((MQUOTIENT) 1 ((MPLUS) ((MEXPT) $X 2) 3)))
(SETQ SIMPEXAMPLE1 '((MPLUS)((MQUOTIENT) 1 ((MEXPT) ((MPLUS) $Y $X) 3))
((MQUOTIENT) ((MPLUS) ((MEXPT) ((MPLUS) $X 2) 8)
((MMINUS) ((MTIMES) 2 $Y)))
((MEXPT) ((MPLUS) $Y $X) 8))))
(SETQ RADCANEXAMPLE '((MQUOTIENT)((MEXPT)((MPLUS)
((%LOG)((MPLUS)((MEXPT) $X 2) $X))
((MMINUS) ((%LOG) $X)))
$B)
((MEXPT)((%LOG)((MPLUS) $X 1))((MQUOTIENT) $B 2))))
(DEFUN NUMCHK (NUM)
(TERPRI)
(DO ANS (RETRIEVE NIL NIL) (RETRIEVE NIL NIL) NIL
(COND ((EQ '$NO ANS)
(TERPRI) (PRINC '|Well, all right, I'll show you.|)
(TERPRI)(PRIN1 NUM)(PRINC '|;|)(RETURN (TERPRI)))
((NOT (EQ (TYPEP ANS) 'FIXNUM))
(TERPRI)(PRINC '|That isn't a number.|)
(TERPRI)(PRINC '|Try again.|)(TERPRI))
((AND (> ANS 0)(NOT (> ANS NUM)))(RETURN (TERPRI)))
(T (TERPRI) (PRINC '|That number isn't in the list. Try again.|)
(TERPRI)))))
(DEFUN QUITCHK ()
(TERPRI)
(DO ((X (TYI)(TYI))) (NIL)
(COND ((OR (= X 103) (= X 71))
(TERPRI)
(PRINC '|That was just a G, try again.|)
(TERPRI)
(PRINC '|Hold down the control key.|)(TERPRI))
((= X 7)
(TERPRI)
(PRINC '|That's it, very good.|)
(TERPRI)
(PRINC '|Now we'll make it a quit character again, so|)
(TERPRI)
(PRINC '|only type it if you want to quit out of the PRIMER.|)
(RETURN (TERPRI)))
(T (TERPRI)
(PRINC '|Nope, not quite. Try again, hold down the control key|)
(TERPRI)
(PRINC '|and hit the G.|)(TERPRI)))))