Category : Miscellaneous Language Source Code
Archive   : MAX.ZIP
Filename : TUTOR.DOC

 
Output of file : TUTOR.DOC contained in archive : MAX.ZIP

Max Version 1.00 - Getting Started


Max is a programming language. To understand what that means,
take a few minutes to compare it to English. In English, if you don't
want to forget to go to your dentist appointment you might say, "Joe,
don't let me forget to go to my dentist appointment." Now Joe has to
remember to tell you about your dentist appointment. He might remember
later in the day when he looks at the clock. He might forget all about
it. In Max, you could say:

set (note "dentist appointment")

to tell the computer that you have a dentist appointment. The computer
would remember this important piece of information, possibly forever. But
the purpose was to remind you, so you would also have to tell the computer
to remind you. In Max, you could do this by saying:

if (quit (then (print (note))))

Since note was set earlier to "dentist appointment" this would remind you
when you got ready to quit for the day. The point of all this is that in
English you can tell people what to do and in Max you can tell computers
what to do. There are really quite a few similarities between the English
language for people and the Max language for computers.

English has lots of words. These words represent things or ideas
or actions or just about anything we can think of. They also fit together
in a neat system of classes and descriptions. Lets consider how words can
be assigned meaning. For example consider the word "weather." If I were to
say that the weather is rainy, it's as if I gave
the word weather a new meaning in the context of our discussion. If
someone else asked, "what's the weather?" I could then say "it's rainy."
Later, when the sun came out, I could say "the weather is sunny," and
I would have given weather a new meaning.

Max has lots of words too. Many of the words are action words,
kind of like verbs. For instance, if you want someone to tell you the sum
of three and four you tell them to "add three and four." It just so happens
that "add" is a word in Max too. And it even means the same thing! If you
want Max to add three and four just tell it:

add (3 4)

and presto, it does. In Max these "verbs" are called functions.

In Max you can make words take on new meaings, and you can even
create new words when you need to. These special words that can take on
new meanings are called variables. In Max, if we want to remember that the
weather is rainy we can say:

set (weather "rainy")

and voila! Max has remembered what the weather was. If someone else
wants to know what the weather is we can have Max tell them:

print (weather)

This doesn't print "weather" because we made weather take on a new
meaning with the "set" line above. It prints "rainy" instead. Later if it
gets sunny we can keep Max up to date with:

set (weather "sunny")

Besides words, English has lots of punctuation too. Just look
at it all over the preceding paragraphs. It's there for a reason:
without it it would be much harder to figure out where one thought ended
and the next began. The same is true for Max. Max doesn't have as much
punctuation as English but what it does have is very important. Remember when
we said that Max could add three and four by telling it "add (3 4)"?
The reason we used the parentheses was so that Max could figure out what
we wanted it to add. Without the left parenthesis it wouldn't have known
when to start adding and without the right parenthesis it wouldn't have
known when to stop. Everything between the parenthesis is called an
argument list. Why argument list? Ask a mathematician.

There's one more type of word in Max, and it's not at all like
the variables. In fact it's almost exactly the opposite. It can never
take on a new meaning. These words are called literals and the way we
distinguish them from variables is by putting them in quotation marks
(oh no! more punctuation). In the previous examples, "sunny" and "rainy"
were both literals. Literals don't have to be just one word, in fact
any number of words surrounded by quotation marks is a literal, so the
phrase "dentist appointment" in the first paragraph is a literal too.

So there you have it -- the basic elements of the Max programming
language. Lets recap:

Functions - These tell Max to do something, like add, and
can be followed by an argument list which specifies some
things to act on, like (3 4) in the add example.

Variables - These are names which can take on other meanings,
and once they are given a new meaning they remember it until
told something else, like weather in the example.

Literals - These are names (or phrases) that never take
on different meanings. They are always surrounded by quotation
marks to distinguish them from variables.

In addition to these basic elements there are a few other things that
make it possible to program in Max. These are:

Argument List Initiators - Despite the long name these are
very short symbols, like left parenthesis, left square bracket
and left curly bracket. Each one marks the start of arguments
to a function.

Argument List Terminators - Yup, you guessed it... these
symbols mark the end of an argument list and each one matches
the corresponding argument list initiator, so we have right
parenthesis, right square bracket and right curly bracket.

Comment Initiator - There's just one of these, the lowly
semicolon. The semicolon and anything following it up to the
end of the line are completely ignored by Max. This is so you
can write a note to yourself in the program. Max won't try
to read it and get confused, but you can read it and it might
remind you, or someone else, what you were originally up to.

White Space - The tab, end of line, and space characters are
known as white space. These are used by Max, along with argument
list initiators, argument list terminators and quotation marks
to decide where one word ends and the next begins. White space
outside a literal is pretty much ignored beyond that purpose,
whereas white space inside a literal is part of the literal.

And that's it... everything you need to know about Max, at least to get
started. Most of the rest of Max is just learning about all of the
functions that are available, and figuring out how to create your own
functions when you need to.

Perhaps the best way to start programming in Max is to just work
through a few examples. This is best done right at the computer, where you can
type in the examples and see for yourself that it works like it's supposed
to. If you have MaxEdit, the integrated editor for the PC, you're in luck
because you can display this text in one window and type in the example
in the other. Unfortunately you have to learn to use MaxEdit to do this,
but it's fairly simple and you only need to use a few commands to get
started. See the MaxEdit guide for more information. If you don't have
a PC or MaxEdit, just type in the example. If you make a typing mistake
just use backspace to go back and correct it. If you don't notice the
mistake until you're on the next line, you will have to enter Control-C
and start over again. By the way, Control-C can be used at any time to
tell Max to stop what its doing and wait for new functions. Control-C
is entered by holding down the key marked "Control" and pressing "C".

So now for the example. This example illustrates all of the elements of
Max that we've talked about. It also shows how to create a new function.
The reason we are going to create a new function is because Max does not
have a builtin function to do what we want to do. What is it that we
want to do? We want Max to ask us our name and then tell us the time.
Useful? Not really, but it makes a good example. Without further ado:

define (
sample (
print ("What is your name?")
input (name)
print ("Thanks " name ". The time is " time ())
)
)

Now that you know about all of the elements of Max you can take a look
at that program and say, "look at all of those functions, variables and
literals," and your buddy might add, "not to mention the argument
list initiators, and terminators!" Actually that's probably not how
it would go at all. What you would really do is concentrate on what
those elements of Max are trying to do.

The word "define" is obviously a function since it's followed by an
argument list initiator. Actually, "define" is one of the most important
functions in Max because it lets you define a new function of your own.
And that's what's happening here. We are defining a new function called
sample.

The next part is just a bit confusing. Don't worry too much about it
now -- it will all make sense later. We've specified some arguments to
this new function called sample. These arguments are our way of defining
sample. What has happened is that we've created a new function called
sample by specifying which old functions it represents. The new function
sample then is defined to be a sequence of the old functions print, input
and print. Old functions that are always available are called builtin
functions. Part of the strength of Max lies in its large set of builtin
functions.

The rest is a breeze. We know what print does from before. It prints
its argument list. The built-in function "input" is sort of the reverse
of print. It reads a value from the terminal and saves it in the
variable specified by its argument. So in this sample function, input
reads whatever gets typed at the terminal after "What is your name?"
is printed. It saves this in a variable called "name". Since we can
make up any name we want for a variable, it makes sense to choose one
that has something to do with the information that it will hold. This
one holds the name of the user so we chose "name".

After getting a name the next step is to print some more things. The
print statement displays "Thanks " and then whatever was entered in
response to "What is your name?". It doesn't print "name" because name
is a variable and it took on a new value. Next the computer prints a
period immediately following whatever was stored in name. It follows
it immediately because the intervening white space was discarded. The
computer then prints "The time is " (that space actually gets printed
because it is part of the literal) and whatever value is returned by
the builtin function called "time". This function returns the current
system time. By return, we mean it takes on that new value. You might
ask, "if both name and time take on a new value, then what is the
difference between a variable and a function?" The answer is that a
variable takes on a value when we set it, whereas a function performs
some action that might make it take on a value. The function time is a
good example of this. It's function is to take on the value of the current
system time whenever it's referenced. The print function, on the other
hand, doesn't take on a new value. That's not its purpose. All of this
is a bit off the point and it's sometimes best to take things on faith
initially and then think about it again some more later when it's not
so confusing.

There's one last thing to notice about the reference to time in the
Max program fragment. It doesn't have any arguments in its argument
list. This is because it doesn't need any. The parentheses are needed,
however, to tell Max that it's a function. For this reason we just use
a left parenthesis followed by a right parenthesis.

The last two right parentheses on the last two lines of the function
match up with the first two left parentheses. In fact, all of the parentheses
are matched. This is important because Max needs to know where each
argument list begins and where it ends. The last two parenthesis close
the argument lists for the sample function and the define function.

The indenting of some of the lines isn't necessary for Max (spaces
outside of literals are ignored) but it helps us to pair up the
parentheses. Another way to pair up argument list terminators with
corresponding argument list initiators is to use a mixture of parentheses,
square brackets and curly brackets. Just pair each left square bracket
with a right square bracket and each left curly bracket with a right curly
bracket. This allows us to scan through the code visually and make sure
everything matches up.

Your new function is called a user defined function because you
defined it. The two types of functions, then, are builtin functions and
user defined functions. Builtin functions are always available and are
provided as part of the Max programming language. User defined functions
are available once they hsave been defined. User defined functions can be
used in the definition of other user defined functions. After they are
initially defined, they are just like builtin functions.

What do you do next? Browse through the Max reference manual and
try to get an overview of the builtin functions. Start with the
general purpose ones, like arithmetic and string handling. Pay particular
attention to the flow-of-control functions. These allow your program to
loop, i.e. perform a task repetitively. Before you know it, Max will be
a breeze. Good luck.


  3 Responses to “Category : Miscellaneous Language Source Code
Archive   : MAX.ZIP
Filename : TUTOR.DOC

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/