Google
 

Trailing-Edge - PDP-10 Archives - decuslib10-01 - 43,50150/alis.sno
There are 2 other files named alis.sno in the archive. Click here to see a list.
*
*	THIS PROGRAM USES PROGRAMMER-DEFINED DATA TYPES TO
*	REPRESENT AN ARBITRARILY LONG INTEGER AS A LINKED LIST
*	CALLED ALI.  OPSYN IS USED TO DEFINE A BINARY OPERATOR
*	AND TWO UNARY OPERATORS FOR MANIPULATING ALIS.
*
*	% APPENDS A NODE TO THE HEAD OF A LIST.  # AND / RETURN
*	THE VALUE OF THE HEAD OF THE LIST, AND THE LIST LINKED
*	FROM THE HEAD, RESPECTIVELY.
*
*	THE OPERATORS + AND * ARE GENERALIZED TO RETURN INTEGERS
*	IF THE OPERANDS ARE INTEGERS AND THE RESULT LESS THAN
*	MAX (10000).  IF THE RESULT IS GREATER THAN MAX, AN ALI
*	IS GENERATED WITH THE VALUE OF THE HEAD EQUAL TO THE LOW
*	ORDER DIGITS, AND THE LINK POINTING TO AN ALI WITH THE
*	HIGHER DIGITS.  IF EITHER OPERAND IS AN ALI, THE RESULT
*	IS AN ALI.
*
*	THE USE OF ALIS IS ILLUSTRATED BY COMPUTING THE FIRST K
*	POWERS OF AN INTEGER N.
*
*
	&ANCHOR = 1
	OPSYN('SUM','+',2)
	OPSYN('PROD','*',2)
	DATA('ALI(V,L)')
	DEFINE('OUT(OUT)')
	DEFINE('APPEND(V,L)')
	DEFINE('ADD(I1,I2)C')
	DEFINE('MUL(I1,I2)C')
	DEFINE('VAL(VAL)')
	DEFINE('LINK(I)')
	OPSYN('+','ADD',2)
	OPSYN('*','MUL',2)
	OPSYN('%','APPEND',2)
	OPSYN('/','LINK',1)
	OPSYN('#','VAL',1)
	MAX	=  10000
	ADDFIX  =  RTAB(SIZE(MAX) - 1) . C REM . ADD
	MULFIX  =  RTAB(SIZE(MAX) - 1) . C REM . MUL
*		FUNCTION DEFINITIONS
*
						:(FEND)
*
APPEND	APPEND   =  ALI(V,L)			:(RETURN)
*
*
ADD	ADD      =  IDENT(I2)  I1		:S(RETURN)
	ADD	 =  IDENT(I1)  I2		:S(RETURN)
	ADD	 =  SUM(#I1,#I2)
	 LT(ADD,MAX)  INTEGER(I1)  INTEGER(I2)	:S(RETURN)
	ADD	 =  LT(ADD,MAX)  ADD % (/I1 + /I2)   :S(RETURN)
	ADD	ADDFIX
	ADD	= ADD % (C + (/I1 + /I2))	:(RETURN)
*
LINK	LINK	=  \INTEGER(I)  L(I)		:(RETURN)
*
VAL	VAL	=  \INTEGER(VAL)  V(VAL)		:(RETURN)
*
*
*
OUT	OUT	=  IDENT(/OUT)  #OUT		:S(RETURN)
	OUT	=  OUT(/OUT) DUPL('0',SIZE(MAX) - SIZE(#OUT) - 1)
+				#OUT		:(RETURN)
*
*
MUL	MUL	=  DIFFER(#I1) DIFFER(#I2) PROD(#I1,#I2) :F(RETURN)
	LT(MUL,MAX) INTEGER(I1)  INTEGER(I2)	:S(RETURN)
	MUL	=  LT(MUL,MAX)  MUL % ( I1 * /I2  +  I2 * /I1)
+						:S(RETURN)
	MUL	MULFIX
	MUL	=  MUL % (C +  I1 * /I2  +  I2 * /I1)
+						:(RETURN)
FEND
	N	=  256
	K	=  15
	P	=  1
	OUTPUT	=  'POWERS OF '  N
	OUTPUT	=
L	I	=  LT(I,K)  I + 1		:F(END)
	P	=  P  *  N
	OUTPUT	=  I  ': '  OUT(P)		:(L)
END