Scheme programming examples
- example1.scm, which displays a
- example2.scm, which displays a
blue disk that gets larger each second.
- example3.scm, which displays
the word "hello" in green, 18-point font, and adds on the letter "d" at
the end each second.
- example4.scm, which displays
a digital counter (in green, 18-point font) which increases by one each
- example5.scm, which is just
like example 2 except that it stops when the disk reaches a diameter of
- example6.scm, which displays a
blue disk that moves right or left when you press the right or left
arrow on the keyboard.
- example7.scm, which displays a
blue disk that moves right, left, up, or down when you press the
corresponding arrow on the keyboard. Note that this requires using a
posn as the world, rather than something simple like a
number or a string.
- switch-color.scm, which
displays a disk that switches colors between red and green every second,
representing the state of the world with a boolean (true for red, false
which behaves the exact same way but represents the state of the world
with a string ("red" or "green").
April 21: local and auxiliary functions
which computes the largest of a list of numbers. It takes an incredibly
long time to find the largest of an increasing list.
which does the same thing much faster by using a local variable.
which uses an auxiliary "bigger" function instead.
which puts the auxiliary "bigger" function inside a local definition.
Unfortunately, this redefines the "bigger" function once for each
element of the list, which seems inefficient. So...
which defines "bigger" locally once, along with a recursive
"helper" function, and the main "largest" function simply calls "helper"
in the presence of "bigger".
which sorts a list of numbers in increasing order.
which does the same thing with the auxiliary function defined locally.
which defines both the auxiliary function and a recursive "helper"
function locally, so the auxiliary function is only defined once.