WSFN (programming language)
WSFN (Which Stands for Nothing) is an interpreted programming language for controlling robots created by Li-Chen Wang.[1] It was designed to be as small as possible, similar to Wang's earlier effort, Tiny BASIC.[2]
The language consisted primarily of single-letter commands to tell the robot to move in certain directions, while others performed tests or basic mathematical operations. It was first published in Dr. Dobb's Journal in September 1977. This version included code that simulated the robot as a cursor on the VDM-1 display, or graphically on a Cromemco Dazzler display. Today these would be known as turtle graphics. It was later translated into Japanese and published by ASCII.[1]
Extended WSFN was an implementation created for the Atari 8-bit family of home computers written by Harry Stewart and published by the Atari Program Exchange[3] in 1981.[4] In addition to supporting turtle graphics, it added a number of commands to control the graphics and sound capabilities of that platform. It was offered as a "beginner's language with emphasis on graphics". In this respect, it is similar to the PILOT programming language, although with additional control constructs.
Basic syntax
WSFN consisted of a number of single-letter commands to control the movement of the turtle.[5]F
would move the turtle Forward one step, while 25F
would move 25 steps forward. R
and L
made the turtle turn one unit to the Right or Left, respectively, while it could also be pointed N
orth. The step sizes and turn units were defined by the hardware, but were set to one pixel and 45 degrees in the turtle graphics versions. H
returned it Home in the center of the screen and C
Cleared any previous drawing. Thus, one could draw a square on the screen with the string:[6]
BCWHN25F2R25F2R25F2R25F
These instructions set the color to Black and Clears the screen (to black), sets the color to White, Homes the turtle, resets the turtle to point North, then draws a series of four lines 25 steps long, rotating 90 degrees between each one.
Lists of commands could be surrounded in parenthesis to create macros. For instance, the same square could be drawn by placing the code to draw one side of the square inside the parenthesis, and then calling it four times:[6]
BCWHN4(25F2R)
Macros could be called within other macros. For instance, this code draws a series of eight squares, each offset by 45 degrees, rotating around the center of the screen:[6]
BCWHN8(4(25F2R)R)
Macros could be assigned a name using the D
efine command (Extended WSFN used =
instead). This code defines a macro with the name "Z" and then calls it as part of a loop:[7]
DZ4(25F2R) BCWHN8(ZR)
WSFN has rudimentary math capabilities consisting of a single accumulator A
that can be incremented and decremented with +
and -
. The letter A
could be placed anywhere a number would appear. So, one could make the series of squares grow larger by incrementing the accumulator 5 times between each step:[5]
25A DZ4(AF2R) BCWHN8(Z5+AR)
Program control was equally rudimentary, consisting of a number of similar commands that handled IF/THEN/ELSE structures. The most basic form was the T
est command, which followed one of two paths if the accumulator was greater or equal to zero. For instance, this command will cause the turtle to turn 90 degrees left if the accumulator is non-zero, or 45 to the right if it is zero:[5]
T(2L)(R)
Variations on the T
branching construct include the ?
, which randomly jumps to the first or second branch 50% of the time, and S
ensor, which tested if the contact sensor on the robot had triggered.[8] Extended WSFN modified the S
to return the color in front of the turtle, allowing hit detection on previous drawing, and added the E
dge test, which jumped to the right side macro if the turtle hit the edge of the drawing area.[9] The original WSFN lacked an equivalent of E
, and instead wrapped the drawing area so the turtle re-appeared on the opposite side of the screen.[5] Extended WSFN optionally supported playfield wrapping as well.[10]
Because it used one-letter commands and recursive syntax, WSFN code is exceedingly cryptic. For example, this is a WSFN program to draw Sierpiński curves:[11]
DIT(-I2FI5RG5RI2FI+)2R DG4F DY (HN63F2R61FRC4 (2FI))
A key concept of Extended WSFN was that the keyboard was always active, even while macros were running. This allowed keyboard input to interrupt running programs. Using this technique, one could make macros for moving the turtle in certain ways, assign them to letters on the keyboard, and then perform these movements by pressing different keys in succession.[12]
Keywords
From the original Dr. Dobbs article.[13]
Keyword | Description |
---|---|
A | Loops by the value of the accumulator (A- sets it to zero, A+ doubles it) |
B | Set the drawing color to black |
C | Clear screen (fill with current color) |
D | Define macro |
F | Move the turtle forward |
H | Return the turtle to the home position |
L | Rotate the turtle to the left |
N | Point the turtle north (up) |
R | Rotate the turtle to the right |
S | Test contact sensor on the robot (IF/THEN/ELSE) |
T | Test for non-zero accumulator (IF/THEN/ELSE) |
W | Set the drawing color to white |
= | Define a macro name |
? | Random test, like T but follows each branch 50% of the time |
+ | Increment accumulator |
- | Decrement accumulator |
From the Extended WSFN manual.[14]
Keyword | Description |
---|---|
B | Beep |
D | Pen down |
E | Tests if the turtle is at the screen edge |
P | Set the pen color to the value in the accumulator |
S | Set the accumulator to the color in front of the turtle (Sense, as in the original version) |
U | Pen up |
W | Wait one jiffy (1⁄30 of a second) |
= | Define macro |
=# | Define variable |
# | Loops by the value in a variable |
* | Adding * to the directional commands, *L or *R, changed the angle to 22.5 degrees instead of 45 |
$ | Test joystick against selected direction (IF/THEN/ELSE) |
% | Read value of paddle controller into accumulator |
& | Write value in accumulator to selected color register |
; | Read the direction of the turtle, 0 through 7, into the accumulator |
@ | Set the accumulator to zero (same as A- in WSFN) |
References
Citations
- ^ a b Li-Chen Wang Talk page at USCS ECE Wiki
- ^ Wang, Li-Chen (May 1976). "Palo Alto Tiny BASIC". Dr. Dobb's Journal of Computer Calisthenics & Orthodontia, Running Light Without Overbyte. 1 (5): 12–25.
- ^ APX listing at atariarchives.org
- ^ Stanford University library "Games E" collection listing
- ^ a b c d Wang 1977, p. 334.
- ^ a b c Stewart 1982, p. 4.
- ^ Wang 1977, p. 345.
- ^ Wang 1977, p. 334,335.
- ^ Stewart 1982, p. 10.
- ^ Stewart 1982, p. 3.
- ^ Wang 1977, p. 336.
- ^ Stewart 1982, p. 5.
- ^ Wang 1977.
- ^ Stewart 1982.
Bibliography
- Wang, Li-Chen (September 1977). "An Interactive Programming Language for Control of Robots". Dr. Dobb's Journal. Vol. 2, no. 8. pp. 334–345.
{{cite magazine}}
: Invalid|ref=harv
(help) - Stewart, Harry (1982). Extended WSFN (PDF). APX.
{{cite book}}
: Invalid|ref=harv
(help)