Scheme programming examples
Animations
- example1.scm, which displays a
blue disk.
- 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
half second.
- example5.scm, which is just
like example 2 except that it stops when the disk reaches a diameter of
40.
- 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
for green).
- switch-color-2.scm,
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
- largest_v1.scm,
which computes the largest of a list of numbers. It takes an incredibly
long time to find the largest of an increasing list.
- largest_v2.scm,
which does the same thing much faster by using a local variable.
- largest_v3.scm,
which uses an auxiliary "bigger" function instead.
- largest_v4.scm,
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...
- largest_v5.scm,
which defines "bigger" locally once, along with a recursive
"helper" function, and the main "largest" function simply calls "helper"
in the presence of "bigger".
- sort_v1.scm,
which sorts a list of numbers in increasing order.
- sort_v2.scm,
which does the same thing with the auxiliary function defined locally.
- sort_v3.scm,
which defines both the auxiliary function and a recursive "helper"
function locally, so the auxiliary function is only defined once.