|A||Add 1||Simple variable||Adds 1 to variable defined by V.|
|B||Begin loop||counter||Starts loop counter at 1. Counter used by N or any statement needing a number.|
|C||Colour||colour number||Sets colour used by P. Doesn't paint anything itself|
|D||Direction||direction number||D0 right, D1 down, D2 left, D3 up, D4-D7 diagonal. Doesn't change position|
|E||Else||no operand||Comes after I or R and gives alternative block of statements.|
|F||Flood universe||colour number||Paints whole universe same colour|
|G||Go||number of squares||Changes position in current direction (without painting anything)|
|H||Highest random||number||This limits the range of random numbers|
|I||If current square is||colour number||Statements dependent on this start with .|
|J||Jump to position||position id||Jumps to position and direction set up by K|
|K||Keep position||position id||Remembers current position and direction - this will be used by J|
|L||Limit||number of times||This is the loop limit (B - N)|
|M||Move||number of squares||Moves current square along number of squares, shuffling the others back|
|N||Next||counter||Add 1 to loop counter. If less than (L), return to start of loop defined by (B)|
|O||Option slow run||length of time||Puts a pause after each instruction so you can watch it working|
|P||Paint||number of squares||Uses colour set by S.|
|Q||Quit program||no operand||Quits program at this point|
|colour number||Quits if current square is this colour|
|R||if Random number =||number||Statements dependent on this start with .|
|S||Square||colour number||Colours one square|
|T||Turn clockwise||number of right angles||Changes direction. Either turns D0-D3 or D4-D7|
What happens if you go outside the universe |
U0 (default) stops program
U1 will move onto opposite edge
U2 moves X to opposite edge and next Y
U3 returns to centre
U4 returns to centre and clears screen
U5 bounces off edge of universe
U6 moves X to start of line but invalid Y stops program
|V||Set Variable||variable||Sets variable to current square's colour. Used by A, Z or statement needing number|
|W||Wait||length of time||Puts a pause at this point so you can watch it working|
|X||Set horizontal position||square number||Changes position - X0 is left-hand edge|
|Y||Set vertical position||square number||Changes position - Y0 is bottom edge|
|Z||Set variable to Zero||variable||Sets variable to zero. Used by A, Z or statement needing number|
|X||4||This is roughly the middle of the universe|
|Colour||6||A blue square|
|Maximum random number||9|
|Universe option||0||Program stops if you go outside universe|
|A common programming language used by young British school children is Logo. This was designed to control a simple robot called a turtle. If you are used to Logo, then P in Unicorn acts like Pen down, Forward, and G acts like Pen up, Forward, and T acts like Right turn 90 degrees. There is no Back in Unicorn (use T2 P4 T2) or Left (use T3). There is also no angle apart from multiples of right angles. The line drawn in Unicorn is made of squares which are quite large, so the numbers used by P are usually single digit, and the line drawn very thick. You can also specify a 'colour' as a character, like a little person or a star, which instantly brings the program to life.|
|These absolute instruction types do not exist in Logo, since a turtle has no knowledge of where it exists, so it can only move relative to its current position, or turn. But children can find this very frustrating, if they know that they want to go up the screen, and can't work out how to turn to get there. Also, it may take several moves and turns to get to a precise spot. These absolute instructions will do it a lot quicker.|
|I don't think that this basic animation feature exists at instruction level in any other language. It does, of course, fulfil no logical function at all. But it will make the programming a lot more fun, and children will see the program in action, rather than just looking at the end result.|
If statements often cause trouble in any language! Most computer languages signal the beginning and end of the If statement, using 'begin ... end' or brackets, or 'endif' or 'fi' (my favourite!).
However, once you start nesting If statements, then either you or the language can get very lost as to which statement belongs in which If statement.
Since the 'begin ... end' or brackets may signal the start and end of loops and functions as well, leaving out an 'end' or bracket can have really extraordinary consequences for your program, as half the program disappears inside the If statement.
Unicorn avoids this by signalling every single statement that is inside the If statement.
It also automatically indents the If statement on the listing, so if you have made a mistake it should be easy to spot.
It uses a completely different technique for loops (see below) so you won't get the two muddled.
Experienced programmers may be confused that the If statement only tests the colour of the current square, and cannot test, for example, the value of a variable. Unicorn is based on a Turing machine, which has a similar limited capability. It means that only visible things are tested, as opposed to things held by the program which you can't see. This concrete form of programming makes it easier for children to work out what's going on - necessary when the program doesn't do what you expect!
By labelling both the start and end of loops with the same character, it means that multiple loops do not get confused with each other.
It also means that loops may not only be nested but 'linked' with the relevant B and N for the different loops not happening in strict sequence - a very unstructured procedure!
However the results are well-defined, and if you don't understand them, then don't nest loops!
You cannot alter the value of a loop counter yourself, and you cannot use it once you have exited the loop.
|Loop counters are one type of variable in Unicorn, and position identifiers used by K and J are another. You cannot alter a position identifier except by another K. You cannot use the same character for different types of variables in the same program.|
|This is the third type of variable. You cannot alter it except by another V.|
|This is the fourth, and last, type of variable. Please note that this is the only type of variable that you can do any arithmetic on, you can only add to it, you cannot test it, and I suspect that you can always avoid using it. But these instructions are here for people whose loops are one adrift from what is required, who just want to get their programs working. Unicorn is not language for doing arithmetic, although it's interesting that you can write a counter and an adder (if only in binary), a prime number generator, and a sort (see sample programs). None use the Unicorn Add, and there isn't a compare between values!|
|Random numbers help to make programs quirky, which adds to their interest. You will also get a different result every time you run the program.|
|There are three sorts of If statements in Unicorn, I, R and Q with an operand. Q is the simplest since it has no dependent statements.|
|The complexities of clearing the universe arise because you can change the universe before running the program. You do this by clicking on a colour and then on the universe. This means that you can supply some input to your program. If you do this, use 'Run (no clear)' and 'Step (no clear)', or your carefully prepared universe will get cleared automatically before the program is run.|
|Another way to slow your program down is to use the 'Step program' button. Each time you click this, you get one more statement of the program run. You also get every variable displayed, and the paint colour, and the current square colour, and the direction, and the next line of the program to be run, and there is a cursor showing current position. This means that if there is a problem with the program, you can check everything that's happening, at each statement, to see what's going wrong. That will show you your mistake!|
l4 b$ p t1 n$
c d0 x1 y p d3 x y1 p
b$ p$ t1 n$
s b$ m$ t1 n$
b% s? w7 n%
u2 l b% s? g1 w1 n%
u5 s m w2 d4 m
|Random walk (Will it fall off the top or bottom of the universe?)
u6 h2 x0 s b$ w3 r1 .d4 e .d7 m1 n$
|Multiplication table patterns
u2 l b$ f0 x0 y0 s9 g$ b& s$ l$ b* g1 i9 .s$ .w10 .n$ .q n* n&
|Prime numbers (they're the stars)
u2 f x0 y c p x0 y0 k# c p2 j# l b$ g$ i .j# .n$ .q g$ b& s g$ i .j# .n$ .q w4 n&
|Pretty patterns (click on 'Stop program' if you get bored with it)
x y l10000 b* i0 .c .t1 i .c .t3 i .c .t3 i .c0 .t1 p1 g1 w1 n*
d2 x k# b* b% i .s .g1 .n% s w7 j# n*
|Binary adder (Generates two random numbers, then adds them)
d2 x y k# h2 l5 b% g1 k$ r? .s e .s d1 r? .c e .c g1 p1 g2 p1 j$ n% b* j# d2 g1 k# q0 i .n* d1 g3 i .s .n* s d2 b& g1 i .s .n& s n*
|Group together (click on 'Stop program' if you get bored with it)
u2 x1 y0 d0 k# l b£ s? g1 n£ b! j# i0 .q v@ z* a* b$ g1 i@ .a* .n$ k& t2 m* i0 .n! j& n$
|Sort (click on 'Stop program' if you get bored with it)
u2 x0 y0 d2 k\ g2 l b$ s? g1 n$ l9 b# c# j\ g1 k^ l999 b& j^ i# .t2 .b% .g1 .t2 .m1 .k\ .i0 ..n& .t2 .g1 .n% g1 i0 .n# .q k^ n&
© Jo Edkins 2004