Tuesday, May 25, 2010

Learn to Program in
Scheme 2, Three Simple Observations

 
Here's a Scheme tutorial I
found on the web. The tutorial
is specific to Gimp. However,
it is mostly about Scheme.

Here's the tutorial:

Basic Scheme

I'll make 3 simple observations
about Scheme that I've gathered
from this tutorial:

  1. Everything in Scheme is surrounded
    by parentheses
  2. The first thing you find
    inside the left parenthesis is
    the operation you wish to perform
  3. Comments start with a semi-colon
    character (;)

Making these 3 observations goes a
long ways towards helping me to be
able to read Scheme. That's the first
thing you want to learn when learning
a new programming language. You want
to learn to read before you learn to
write.

Learning to read means learning to
recognize certain things right away.

The first thing I notice about the
script at the bottom of the page is
that many many of the lines start out
as comments. Comments are something
that help you to understand a program
but otherwise, have no bearing on the
actual execution of the program. In
other words, comments are not programming
at all, they are pure literature.

Look for all the semi-colons in the
script at the bottom of the page. If
you don't know what a semi-colon is,
it is a dot (period) on top and a comma
on the bottom. That's the general appearance.
A semi-colon appears as a dot on top of
a comma.

Comments are very helpful. You might want
to look for the semi-colons first and then
read all the comments that follow to the
right of the semi-colons.

Something that seems to characterize
Scheme is parentheses, parentheses,
parentheses. There are parentheses
everywhere.

I suspect that this is so because Scheme
basically views everything as a mathematical
operation. In math, you have the operation
and then you have the arguments to the
operation.

For example, as schoolchildren, we learn
this basic operation:

2 + 2 = 4

The plus sign is the operation and the
numbers that surround the plus sign are
the arguments to that operation. In
fact, I did a little too much. Not only
did I give the operation, I also gave the
result of the operation, the number 4.

What I should really do is just write this:

2 + 2

By only writing the operation and the arguments
to the operation, I'm giving my computer something
to do. It is going to find the answer for me.
Why would I ask my computer to do something for me
when I already know the answer?

So again, our basic operation is this:

2 + 2

In scheme, the operation would be written
like this:

(+ 2 2)

This is what I gather from the tutorial.
Operations are always surrounded by parentheses
and you give the operation before you give
the arguments. Here. I'll summarize this
as two rules:

  1. Operations are surrounded by parentheses
  2. The operator itself appears first inside
    the parentheses

OK. I think I'll leave it at that. From these
3 simple observations, a lot of information can
be extrapolated.

What's the lesson? Start small and build. To
learn a new programming language, you start small
and you build.

To learn Scheme, you make a few simple observations
and you come to as many conclusions as possible from
those simple observations. One observation leads to
another and one day, you know the language.

At least, that's how I've learned other programming
languages. So, I assume that this same simple method
will work with Scheme.

Ed Abbott

No comments:

Post a Comment