Restricted BlooP/FlooP
Jump to navigation
Jump to search
This is a restricted kind of Douglas Hofstadter's BlooP/FlooP programming language. There is no primitive adding, multiplying, and comparing; there is no conditions and no tests; the only primitive is successor operation.
I use the convention that a question mark is just like a letter and that 1 is the same as YES and 0 is the same as NO. It is also assumed that CELLs are local to each procedure.
You can see how many things are not needed:
IF AT MOST QUIT BLOCK ABORT LOOP addition multiplication comparison
Actually, the ABORT LOOP command will be needed inside of a MU-LOOP block. You can assume the command "ABORT LOOP;" aborts the innermost mu-loop.
Add two numbers
Procedure codes =
DEFINE PROCEDURE ADD [X,Y]:
BEGIN:
CELL(0) <- X;
LOOP Y TIMES:
BEGIN:
CELL(0) <- ^CELL(0);
END;
OUTPUT <- CELL(0);
END;
Calculate the predecessor of a number
Procedure codes =
DEFINE PROCEDURE PREDECESSOR [X]:
BEGIN:
CELL(0) <- 0;
CELL(1) <- 0;
LOOP X TIMES:
BEGIN:
LOOP CELL(0) TIMES:
BEGIN:
CELL(1) <- ^CELL(1);
END;
CELL(0) <- 1;
END;
OUTPUT <- CELL(1);
END;
Subtract two numbers
Procedure codes =
DEFINE PROCEDURE SUBTRACT [X,Y]:
BEGIN:
CELL(0) <- X;
LOOP Y TIMES:
BEGIN:
CELL(0) <- PREDECESSOR[CELL(0)];
END;
OUTPUT <- CELL(0);
END;
Check if one number is equal to another
Procedure codes =
DEFINE PROCEDURE EQUAL? [X,Y]:
BEGIN:
OUTPUT <- YES;
LOOP ADD[SUBTRACT[X,Y],SUBTRACT[Y,X]] TIMES:
BEGIN:
OUTPUT <- NO;
END;
END;
Check if one number is greater than another
Procedure codes =
DEFINE PROCEDURE GREATER? [X,Y]:
BEGIN:
LOOP SUBTRACT[X,Y] TIMES:
BEGIN:
OUTPUT <- YES;
END;
END;