Here’s a program for a fish that swims randomly:
-------------------------------------fishimageis@fish-imagedoforever{wait0.02forwardby2turnby(random5)-2}
The ---...- starts a sprite declaration, where the sprite is named fish. In addition, if the file name is "fish-land.rkt", then fish-land is defined as the land where fish starts.
Here’s the grammar of this textual language (click on a keyword for more information):
‹prog›
::=
‹use›*‹sprite›*
‹sprite›
::=
---...-‹id›‹clause›*
|
do ‹statement›*
‹expr›
::=
‹number›|‹image›|‹string›
|
‹id›
|
‹expr›‹binary-op›‹expr›
|
‹unary-op›‹expr›
|
random ‹expr›
|
touches ‹expr›
|
(‹expr›)
|
wait ‹expr›
|
say ‹expr›
|
|
|
|
watch ‹expr›
|
forever {‹statement›*}
|
while ‹expr›{‹statement›*}
|
if ‹expr›{‹statement›*}
|
‹id›=‹expr›
‹unary-op›
::=
-
|
+
‹binary-op›
::=
+|-|*|/|<|>|<=|>=|=
‹key›
::=
‹id›|+|-|*|/|<|>|=
‹id›
::=
a letter (in a/A to z/Z) followed by letters, numbers, and _s
|
@ followed by a sequence of letters, numbers, _s, and -s
‹number›
::=
a decimal number
‹string›
::=
sequence of characters between "s
syntax
use ‹id›
syntax
do ‹statement›*
syntax
random ‹expr›
syntax
touches ‹expr›
syntax
wait ‹expr›
syntax
say ‹expr›
syntax
syntax
watch ‹expr›
syntax
forever {‹statement›*}
syntax
while ‹expr›{‹statement›*}
syntax
if ‹expr›{‹statement›*}