08/01/72  - GLS -

THE LISP TRACE PACKAGE CONSISTS OF THREE MAIN FUNCTIONS,
TRACE, UNTRACE, AND REMTRACE, ALL OF WHICH ARE FEXPRS.

A CALL TO TRACE HAS THE FOLLOWING FORM:
	(TRACE <TRACE SPECS>)
A "TRACE SPEC" IN TURN IS EITHER AN ATOM (THE NAME
OF THE FUNCTION TO BE TRACED) OR A LIST OF THIS FORM:
	(<FUNCTION NAME> <OPTIONS>)
WHERE THE OPTIONS ARE AS FOLLOWS:

BREAK <PRED>    CAUSES A BREAK AFTER PRINTING THE ENTRY
		TRACE (IF ANY) BUT BEFORE APPLYING THE
		TRACED FUNCTION TO ITS ARGUMENTS, IF
		AND ONLY IF <PRED> EVALUATES TO NON-NIL. 

COND <PRED>     CAUSES TRACE INFORMATION TO BE PRINTED
		FOR FUNCTION ENTRY AND/OR EXIT IF AND
		ONLY IF <PRED> EVALUATES TO NON-NIL.

ENTRYCOND <PRED> CAUSES TRACE INFORMATION TO BE PRINTED FOR
		FUNCTION ENTRY IF AND ONLY IF <PRED> EVALUATES TO
		NON-NIL. IF BOTH COND AND ENTRYCOND ARE USED, THE
		<PRED> SPECIFIED FOR COND IS EVALUATED FIRST; AND
		BOTH <PRED>'S MUST EVALUATE TO NON-NIL FOR
		ENTRY TRACE INFORMATION TO BE PRINTED. IS THE
		<PRED> FOR COND EVALUATES TO NIL, THEN THE <PRED> FOR
		ENTRYCOND WILL NOT BE EVALUATED.

EXITCOND <PRED>	CAUSES TRACE INFORMATION TO BE PRINTED FOR
		FUNCTION EXIT IF AND ONLY IF <PRED> EVALUATES TO
		NON-NIL. IF BOTH COND AND EXITCOND ARE USED, BOTH MUST
		EVALUATE TO NON-NIL FOR EXIT TRACE INFORMATION TO BE
		PRINTED. NOTE THAT THE <PRED> FOR COND IS
		NOT RE-EVALUATED ON EXIT; RATHER, ITS VALUE ON ENTRY
		IS SAVED. IF THIS VALUE IS NIL, THEN THE <PRED>
		FOR EXITCOND WILL NOT BE EVALUATED.

WHEREIN <FN>    CAUSES THE FUNCTION TO BE TRACED ONLY
		WHEN CALLED FROM THE SPECIFIED FUNCTION.
		ONE CAN GIVE SEVERAL TRACE SPECS TO TRACE,
		ALL SPECIFYING THE SAME FUNCTION BUT WITH
		DIFFERENT WHEREIN OPTIONS, SO THAT THE
		FUNCTION IS TRACED IN DIFFERENT WAYS WHEN
		CALLED FROM DIFFERENT FUNCTIONS. NOTE THAT
		IF THE FUNCTION SPECIFIED BY THE WHEREIN
		OPTION IS ALREADY BEING TRACED ITSELF, THE
		WHEREIN OPTION PROBABLY WILL NOT WORK AS
		DESIRED, PROBABLY. (THEN AGAIN, IT MIGHT.)  
		NOTE THAT <FN> MUST BE AN INTERPRETED FUNCTION,
		SINCE THE WHEREIN TRACE INVOLVES ALTERING
		THE CALLING FUNCTION AS WELL AS THE CALLED.

ARGPDL <PDL>    SPECIFIES AN ATOM <PDL> WHOSE VALUE TRACE
		INITIALLY SETS TO NIL. WHEN THE FUNCTION IS
		TRACED, A LIST OF THE CURRENT RECURSION
		LEVEL FOR THE FUNCTION, THE FUNCTION'S
		NAME, AND A LIST OF THE ARGUMENTS IS CONSED
		ONTO THE <PDL> WHEN THE FUNCTION IS ENTERED,
		AND CDR'ED BACK OFF WHEN THE FUNCTION IS
		EXITED. (ACTUALLY, THIS CONSING/CDRING IS DONE BY
		MEANS OF LAMBDA-BINDING, SO THAT IF AN ERROR OR
		OTHER INTERRUPT OCCURS THE <PDL> WILL BE RESET BY
		UNBINDING.) THE <PDL> CAN BE INSPECTED FROM A
		BREAKPOINT, FOR EXAMPLE, AND USED TO
		DETERMINE THE VERY RECENT HISTORY OF THE
		FUNCTION. THIS OPTION CAN BE USED WITH OR
		WITHOUT PRINTED TRACE OUTPUT. EACH FUNCTION
		CAN BE GIVEN ITS OWN PDL, OR ONE PDL MAY
		SERVE SEVERAL FUNCTIONS. 

ENTRY <LIST>    SPECIFIES A LIST OF ARBITRARY S-EXPRESSIONS
		WHOSE VALUES ARE TO BE PRINTED ALONG WITH
		THE USUAL ENTRY TRACE. THE LIST OF
		RESULTANT VALUES, WHEN PRINTED, IS PRECEDED
		BY A \\ TO SEPARATE THEM FROM THE OTHER
		INFORMATION.

EXIT <LIST>     SIMILAR TO ENTRY, BUT SPECIFIES EXPRESSIONS
		WHOSE VALUES ARE PRINTED WITH THE EXIT TRACE.
		AGAIN, THE LIST OF VALUES PRINTED
		IS PRECEDED BY \\.

ARG     	SPECIFY THAT THE FUNCTION'S ARGUMENTS,
VALUE		RESULTANT VALUE, BOTH, OR NEITHER ARE TO
BOTH		BE TRACED. IF NOT SPECIFIED, THE DEFAULT
NIL		IS BOTH. ANY "OPTIONS" FOLLOWING ONE OF
		THESE FOUR ARE ASSUMED TO BE ARBITRARY
		S-EXPRESSIONS WHOSE VALUES ARE TO BE PRINTED
		ON BOTH ENTRY AND EXIT TO THE FUNCTION.
		HOWEVER, IF ARG IS SPECIFIED, THE VALUES ARE
		PRINTED ONLY ON ENTRY, AND IF VALUE, ONLY ON
		EXIT. NOTE THAT SINCE ARG, VALUE, BOTH, NIL,
		SWALLOW ALL FOLLOWING EXPRESSIONS FOR THIS
		PURPOSE, WHICHEVER ONE IS USED SHOULD BE THE
		LAST OPTION SPECIFIED. ANY SUCH VALUES
		PRINTED WILL BE PRECEDED BY A // AND WILL
		FOLLOW ANY VALUES SPECIFIED BY ENTRY OR EXIT
		OPTIONS.


IF THE VARIABLE ARGLIST IS USED IN ANY OF THE EXPRESSIONS
GIVEN FOR THE COND, BREAK, ENTRY, EXIT, OR AFTER-THE-ARG-
VALUE-BOTH-OR-NIL OPTIONS, WHEN THOSE EXPRESSIONS ARE
EVALUATED THE VALUE OF ARGLIST WILL EFFECTIVELY BE A LIST
OF THE ARGUMENTS GIVEN TO THE TRACED FUNCTION. THUS
	(TRACE (FOO BREAK (NULL (CAR ARGLIST))))
WOULD CAUSE A BREAK IN FOO IFF THE FIRST ARGUMENT TO
FOO IS NIL. SIMILARLY, THE VARIABLE FNVALUE WILL EFFECTIVELY
BE THE RESULTING VALUE OF THE TRACED FUNCTION; SINCE THE VALUE
OF THE FUNCTION IS OF COURSE AVAILABLE ONLY ON EXIT
FROM THE FUNCTION, THIS SHOULD ONLY BE USED WITH THE EXIT AND
EXITCOND OPTIONS. ALSO, THE VARIABLE RECURLEV, ON BOTH ENTRY AND
EXIT, WILL EFFECTIVELY HAVE AS ITS VALUE A NUMBER INDICATING THE
CURRENT RECURSION LEVEL (AS WOULD BE PRINTED BY TRACE). THIS
ALLOWS CONDITIONAL BREAKS AND TRACES BASED ON THE DEPTH
OF RECURSION. THE RECURSION LEVEL IS INCREMENTED BY MEANS OF
LAMBDA-BINDING; THUS IF AN ERROR OR OTHER INTERRUPT OCCURS,
THE RECURSION LEVEL WILL BE RESET BY UNBINDING.
(NOTE THAT THE WORD "EFFECTIVELY" IS USED IN DESCRIBING THE
VALUES OF THE ABOVE "VARIABLES" SINCE THESE VARIABLES ARE
NOT ACTUALLY USED; TRACE ACTUALLY PERFORMS A SUBLIS ON THE
EXPRESSIONS FOR THE OPTIONS MENTIONED ABOVE, SUBSTITUTING
CERTAIN NON-INTERNED ATOMS FOR ANY AND ALL APPEARANCES OF
THE SPECIAL "VARIABLES" MENTIONED ABOVE. THEREFORE, DO
NOT TRY TO USE THESE VARIABLES FOR ANYTHING BUT OBTAINING
THEIR VALUES WHEN USING THEM IN EXPRESSIONS FOR THE ABOVE
OPTIONS.)

IN ADDITION TO USING THE VARIABLE ARGLIST, EXPRESSIONS
FOR TRACE OPTIONS MAY REFER TO THE ACTUAL NAMES OF
THE FUNCTION'S ARGUMENTS IF THE FUNCTION IS INTERPRETED RATHER
THAN COMPILED. FURTHERMORE, SUCH ARGUMENT VARIABLES MAY
BE EXAMINED FROM BREAKPOINTS.

 
THERE EXISTS A VERSION OF THE TRACE PACKAGE
CALLED STRACE. IT LOOKS EXACTLY LIKE THE NORMAL TRACE PACKAGE,
EXCEPT THAT ONE EXTRA OPTION IS AVAILABLE:

GRIND		SPECIFIES THAT ANY TRACE OUTPUT IS TO BE DONE,
		NOT WITH THE USUAL CALL TO PRINT, BUT THROUGH THE
		SPRINT FUNCTION FROM THE GRIND PACKAGE; THUS, TRACE
		OUTPUT FOR THAT <TRACE SPEC> WILL BE "PRETTY-PRINTED".

THIS FEATURE IS NOT INCLUDED IN THE REGULAR TRACE PACKAGE
BECAUSE IT REALLY EATS UP FREE STORAGE.



EXAMPLES OF CALLS TO TRACE:

[1] TO TRACE FUNCTION FOO, PRINTING BOTH ARGUMENTS ON ENTRY
AND RESULT ON EXIT:
	(TRACE FOO)  OR  (TRACE (FOO))  OR  (TRACE (FOO BOTH)).

[2] TO TRACE FUNCTION FOO ONLY WHEN CALLED FROM FUNCTION BAR,
AND THEN ONLY IF (CDR X) IS NIL:
	(TRACE (FOO WHEREIN BAR COND (NULL (CDR X))))
     OR (TRACE (FOO COND (NULL (CDR X)) WHEREIN BAR)).
AS THIS EXAMPLE SHOWS, THE ORDER OF THE OPTIONS MAKES NO
DIFFERENCE, EXCEPT FOR ARG, VALUE, BOTH, OR NIL, WHICH MUST
BE LAST.

[3] TO TRACE FUNCTION QUUX, PRINTING THE RESULTANT VALUE
ON EXITING BUT NO ARGUMENTS ON ENTRY, PRINTING THE VALUE
OF (CAR X) ON ENTRY, OF FOO1, FOO2, AND (FOO3 BAR) ON EXIT,
AND OF ZXCVBNM AND (QWERTY SHRDLU) ON BOTH ENTRY AND EXIT:
	(TRACE (QUUX ENTRY ((CAR X)) EXIT (FOO1 FOO2 (FOO3 BAR))
		VALUE ZXCVBNM (QWERTY SHRDLU))).

[4] TO TRACE FUNCTION FOO ONLY WHEN CALLED BY FUNCTIONS BAR
AND BAZ, PRINTING ARGS ON ENTRY AND RESULT ON EXIT, PRINTING
THE VALUE OF (QUUX BARF BARPH) ON EXIT FROM FOO WHEN CALLED
BY BAZ ONLY, AND CONDITIONALLY BREAKING WHEN CALLED BY BAR IF
A EQUALS B:
	(TRACE (FOO WHEREIN BAR BREAK (EQUAL A B))
		(FOO WHEREIN BAZ EXIT ((QUUX BARF BARPH)))).

[5] TO TRACE FUNCTIONS PHOO AND FU, NEVER PRINTING ANYTHING
FOR EITHER, BUT SAVING ALL ARGUMENTS FOR BOTH ON A COMMON PDL
CALLED FOOPDL, AND BREAKING INSIDE PHOO IF X IS NIL:
	(TRACE (PHOO ARGPDL FOOPDL BREAK (NULL X) COND NIL NIL)
		(FU ARGPDL FOOPDL COND NIL NIL)).
THE "COND NIL" PREVENTS ANYTHING AT ALL FROM BEING PRINTED.
THE SECOND NIL IN EACH <TRACE SPEC> SPECIFIES THAT NO ARGS
OR VALUE ARE TO BE PRINTED; ALTHOUGH THE COND NIL WOULD
PREVENT THE PRINTOUT ANYWAY, SPECIFYING THIS TOO PREVENTS
TRACE FROM EVEN SETTING UP THE MECHANISMS TO DO THIS (WHICH
IT WOULD, AGAINST THE POSSIBILITY THAT SOMEDAY NIL MIGHT NOT
EVALUATE TO NIL.)

[6] TO TRACE FUNCTION FOOBAR, PRINTING ARGS ON ENTRY AND
RESULT ON EXIT, PLUS THE VALUE OF MOBY-EXPR ON EXIT, AND
PRETTY-PRINTING THE OUTPUT:
	(TRACE (FOOBAR GRIND EXIT (MOBY-EXPR))).

[7] TO TRACE FUNCTION GHOTI, ONE OF WHOSE ARGUMENTS IS
FISH, PRINTING ALL ARGUMENTS ONLY IF FISH
IS NON-NIL, AND PRINTING ON EXIT ONLY IF THE RESULT IS NOT
A NUMBER:
	(TRACE (GHOTI ENTRYCOND FISH
		      EXITCOND (NOT (NUMBERP FNVALUE)))).

[8] TO TRACE FUNCTION SSEHC, PRINTING TRACE OUTPUT ONLY IF
DRAOB IS NON-ATOMIC, AND EVEN THEN ON ENTRY ONLY IF POHSIB IS
A NEGATIVE NUMBER, BREAKING WHEN THE RECURSION LEVEL IS EITHER
3 OR GREATER THAN 7:
	(TRACE (SSEHC COND DRAOB
		      ENTRYCOND (AND (NUMBERP POHSIB) (MINUSP POHSIB))
		      BREAK (AND NEEUQ (OR (EQUAL RECURLEV 3)
					   (LESSP 7 RECURLEV))))).


TRACE RETURNS AS ITS VALUE A LIST OF NAMES OF ALL FUNCTIONS
SET TO TRACE; FOR ANY FUNCTIONS TRACED WITH THE WHEREIN
OPTION, SAY (TRACE (FOO WHEREIN BAR)), INSTEAD OF RETURNING
JUST THE NAME IT RETURNS A 3-LIST (FOO WHEREIN BAR).
IF TRACE FINDS A <TRACE SPEC> IT DOESN'T LIKE, INSTEAD OF THE
FUNCTION'S NAME IT RETURNS A LIST WHOSE CAR IS ? AND WHOSE
CDR INDICATES WHAT TRACE DIDN'T LIKE. (THIS SHOULD BE SLIGHTLY
MORE HELPFUL THAN THE OOLD TRACE, WHICH SIMPLY RETURNED NIL.)
A LIST OF POSSIBLE ERROR INDICATIONS:

(? WHEREIN FOO)     TRACE COULDN'T FIND AN EXPR, FEXPR, OR
		    MACRO PROPERTY FOR THE FUNCTION SPECIFIED BY THE
		    WHEREIN OPTION; OR THE FUNCTION SPECIFIED WAS NOT
		    ATOMIC.

(? ARGPDL FOO)      THE ITEM FOLLOWING THE ARGPDL OPTION WAS
		    NOT A NON-NIL PNAME-TYPE ATOM.

(? FOO NOT FUNCTION) INDICATES THAT THE FUNCTION SPECIFIED
		    TO BE TRACED WAS NON-ATOMIC, OR HAD NO FUNCTIONAL
		    PROPERTY. (VALID FUNCTIONAL PROPERTIES ARE EXPR,
		    FEXPR, SUBR, FSUBR, LSUBR, AND MACRO.)

(? FOO)		    FOO IS NOT A VALID OPTION.

THUS A CALL TO TRACE SUCH AS
	(TRACE (FOO WHEREIN (NIL)) (BAR ARGPDL NIL))
WOULD RETURN, WITHOUT SETTING UP ANY TRACES,
	((? WHEREIN (NIL)) (? ARGPDL NIL)).

IF YOU ATTEMPT TO SPECIFY TO TRACE A FUNCTION ALREADY
BEING TRACED, TRACE CALLS UNTRACE BEFORE SETTING UP THE NEW
TRACE. IF AN ERROR OCCURS, CAUSING (? <RANDOM>) TO BE
RETURNED, THE FUNCTION FOR WHICH THE ERROR OCCURRED MAY OR
MAY NOT HAVE BEEN UNTRACED. BEWARE!

IT IS POSSIBLE TO CALL TRACE WITH NO ARGUMENTS. (TRACE)
RETURNS AS ITS VALUE A LIST OF ALL FUNCTIONS CURRENTLY
BEING TRACED.




UNTRACE IS USED TO UNDO THE EFFECTS OF TRACE AND RESTORE
FUNCTIONS TO THEIR NORMAL (?) UNTRACED STATE. THE ARGUMENT
TO UNTRACE FOR A GIVEN FUNCTION SHOULD BE ESSENTIALLY WHAT
TRACE RETURNED FOR IT; I.E. IF TRACE RETURNED FOO, USE
(UNTRACE FOO); IF TRACE RETURNED (FOO WHEREIN BAR) USE
(UNTRACE (FOO WHEREIN BAR)). UNTRACE WILL TAKE MULTIPLE
UNTRACE SPECIFICATIONS, E.G. (UNTRACE FOO QUUX (BAR 
WHEREIN BAZ) FUPHOO). CALLING UNTRACE WITH NO ARGUMENTS
WILL UNTRACE ALL FUNCTIONS CURRENTLY BEING TRACED.



REMTRACE, ODDLY ENOUGH, EXPUNGES THE ENTIRE TRACE PACKAGE.
IT TAKES NO ARGUMENTS.