Category:BlooP: Difference between revisions

no edit summary
(→‎Example Code: add a few examples.)
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 1:
{{stub}}{{language|BlooP}}
BlooP and it's sister language Floop are 'theoretical' languages with several implementations, created by Douglas Hofstadter in his book ''Gödel, Escher, Bach'', to demonstrate the halting problem.
 
The name BlooP is short for Bounded Loop, the primary structure of the language. FlooP is identical to BlooP in every way except that it also sorts unbounded loops. FlooP is tiringTuring complete, where BlooP is not. There is also a third, impossible language called GlooP, which can solve the halting problem.
 
BlooP and FlooP have only 1 data type: non-negative integers (natural numbers). There are also only 2 variables (except parameters to procedures): <code>OUTPUT</code>, which is the value returned by a procedure, and <code>CELL(i)</code>, which is an unbounded series of numbers. Some implementations also add string literals, which can only be used by an added <code>PRINT</code> instruction.
 
The operators that exist in BlooP and FlooP are:
*<code><=</code> or <code>⇐</code> : Assignment
*<code>+</code> : Addition
*<code>*</code> or <code>x×</code> (depending on implementation): Multiplication
*<code>></code> : Greater Than
*<code><</code> : Less Than
Line 24:
DEFINE PROCEDURE FACTORIAL [N]:
BLOCK 0: BEGIN
OUTPUT <= 1;
CELL(0) <= 1;
LOOP AT MOST N TIMES:
BLOCK 1: BEGIN
OUTPUT <= OUTPUT ×* CELL(0);
CELL(0) <= CELL(0) + 1;
BLOCK 1: END;
BLOCK 0: END.
Line 39:
DEFINE PROCEDURE MINUS [M,N]:
BLOCK 0: BEGIN
OUTPUT <= 0;
IF M < N, THEN:
QUIT BLOCK 0;
Line 46:
IF OUTPUT + N = M, THEN:
ABORT LOOP 1;
OUTPUT <= OUTPUT + 1;
BLOCK 1: END;
BLOCK 0: END.
Anonymous user