Articulo de referencia

WSFN (programming language)

WSFN ( Which Stands for Nothing ) [ 1 ] is an interpreted programming language for controlling robots created by Li-Chen Wang . It was designed to be as small as possible, a "ti...

WSFN (Which Stands for Nothing)[1] is an interpretedprogramming language for controlling robots created by Li-Chen Wang. It was designed to be as small as possible, a "tiny" language,[2] similar to Wang's earlier effort, Palo Alto Tiny BASIC.[3][4] WSFN was first published in Dr. Dobb's Journal in September 1977.

The language consists primarily of single-letter commands to tell a robot to move in certain directions, while other commands perform tests or basic mathematical operations. These can be grouped into named macros to produce more complex programs. The original version also included code that simulated the robot as a cursor on the VDM-1 display, or graphically on a Cromemco Dazzler display. This is similar to the turtle graphics added to the Logo programming language in 1969.

Extended WSFN is an implementation created for the Atari 8-bit computers written by Harry Stewart and published by the Atari Program Exchange[5] in 1981. In addition to supporting turtle graphics, it adds a number of commands to control the graphics and sound capabilities of that platform. It was offered as an "educational graphics language for beginning programmers".[6]

Syntax

WSFN consists of a number of single-letter commands to control the movement of a turtle or robot. Any of these commands can be repeated by prefixing it with a number.[2] For instance, F moves the turtle Forward one step, while 25F moves 25 steps. R and L make the turtle turn one unit to the Right or Left, respectively, and it can also be reset to point North. The step sizes and turn units are defined by the robot hardware, but are set to one pixel and 45 degrees in the turtle graphics versions. Missing in the robot versions, in the computer versions H returns the turtle Home in the center of the screen and C Clears any previous drawing. Thus, one can draw a square with the string:[7]

BCWHN25F2R25F2R25F2R25F

Estas instrucciones establecen el color de dibujo en negro, borran la pantalla (que se rellena con el color actual), establecen el color en blanco, hacen que la tortuga regrese a su posición inicial, la reorientan para que apunte al norte y luego dibujan una serie de cuatro líneas de 25 pasos de longitud, girando 90 grados a la derecha entre cada línea. El resultado es un cuadrado blanco con su esquina inferior izquierda en el centro de la pantalla. [ 7 ]

Las listas de comandos se pueden encerrar entre paréntesis para crear macros. Por ejemplo, se puede dibujar el mismo cuadrado colocando el código para dibujar un lado del cuadrado dentro de los paréntesis y luego llamándolo cuatro veces: [ 7 ]

BCWHN4(25F2R)

Las macros se pueden llamar dentro de otras macros. Por ejemplo, este código dibuja una serie de ocho cuadrados, cada uno desplazado 45 grados, que giran alrededor del centro de la pantalla: [ 7 ]

BCWHN8(4(25F2R)R)

Se puede asignar un nombre a las macros mediante el Dcomando efine ( =en su lugar se utiliza WSFN extendido). Este código define una macro llamada "X" para borrar la pantalla y reiniciar el dibujo, y otra "Z" que dibuja un cuadrado. Luego las utiliza para dibujar el mismo cuadrado giratorio que en el ejemplo anterior: [ 8 ]

DX(BCWHN) DZ4(25F2R) X8(ZR)

WSFN tiene capacidades matemáticas rudimentarias que consisten en un único acumuladorA que se puede incrementar y decrementar con +y -. La letra Ase puede colocar en cualquier lugar donde podría aparecer un número. Se puede hacer que la serie de cuadrados crezca incrementando el acumulador 5 veces entre cada paso: [ 2 ]

DX(BCWHN) 25A DZ4(AF2R) X8(Z5+AR)

Un efecto secundario de la sintaxis es que A-pondría el acumulador a cero, porque realiza la instrucción de decremento por el número en A. Del mismo modo, A+duplica el valor en el acumulador. [ 2 ]

El control del programa es igualmente rudimentario, y consiste en una serie de comandos que manejan estructuras IF/THEN/ELSE . La forma más básica es el Tcomando est, que sigue uno de dos caminos si el acumulador es mayor o igual a cero. Por ejemplo, este comando hace que la tortuga gire 90 grados a la izquierda si el acumulador no es cero, o 45 grados a la derecha si es cero: [ 2 ]

T(2L)R

Variations on the T branching construct include ?, which randomly jumps to the first or second branch 50% of the time, and Sensor, which tests if the contact sensor on the robot has been triggered.[9] Extended WSFN modified the S to return the color in front of the turtle, allowing hit detection on previous drawing, and added the Edge test, which jumps to the right side macro if the turtle hit the edge of the drawing area.[10] The original WSFN lacks an equivalent of E, and instead wraps the drawing area so the turtle re-appears on the opposite side of the screen.[2] Extended WSFN supports this style of playfield wrapping as an option.[11]

Because it uses one-letter commands and recursive syntax, WSFN code is exceedingly cryptic. For example, this is a WSFN program to draw Sierpiński curves:[12]

DIT(-I2FI5RG5RI2FI+)2R DG4F DY (HN63F2R61FRC4 (2FI))

Note that the definition of the macro "I" includes calls to I within it. This is a key aspect of the WSFN concept; the language is highly recursive in nature, which makes programming self-similar patterns like fractals easy to accomplish in a few lines of code.[12]

A key concept of Extended WSFN is that the keyboard is always active, even while macros are running. This allows keyboard input to interrupt running programs. Using this technique, one can 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. This can be aided by adding the Wait command in places to give the user time to respond as the drawing takes place.[13]

Keywords

From the original Dr. Dobbs article.[14]

From the Extended WSFN manual.[15]

Véase también

Referencias

  1. El libro azul para el ordenador Atari . WIDL Video. 1983. ISBN 9780684179216.
  2. ^ Wang 1977 , pág .334. 
  3. ^ Wang, Li-Chen (mayo de 1976). "Palo Alto Tiny BÁSICO". Diario del Dr. Dobb . 1 (5): 12-25 .
  4. Rauskolb, Robert (diciembre de 1976). "El Tiny BASIC de Palo Alto del Dr. Wang" (PDF) . Interface Age . págs. 92–108 . 
  5. Listado de APX en atariarchives.org
  6. Stewart 1982 , portada.
  7. 1 2 3 4 Stewart 1982 , pág. 4.
  8. Wang 1977 , pág. 345.
  9. Wang 1977 , págs. 334, 335.
  10. Stewart 1982 , pág. 10.
  11. Stewart 1982 , pág. 3.
  12. 1 2 Wang 1977 , pág. 336.
  13. Stewart 1982 , pág. 5.
  14. Wang 1977 .
  15. Stewart 1982 .

Bibliografía

  • Wang, Li-Chen (septiembre de 1977). "Un lenguaje de programación interactivo para el control de robots" . Dr. Dobb's Journal . Vol.  2, n.º  8, págs. 334-345 . 
  • Stewart, Harry (1982). WSFN extendido (PDF) . APX.