rev 485 - trunk/docs/tutorial
SVN User <[email protected]> Fri, 14 May 2004 14:02:25 -0400
| Newsgroups | gmane.comp.lang.prothon.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: mark
Date: 2004-05-14 14:02:22 -0400 (Fri, 14 May 2004)
New Revision: 485
Added:
trunk/docs/tutorial/tutorial5.htm
Modified:
trunk/docs/tutorial/index.htm
trunk/docs/tutorial/tutorial2.htm
trunk/docs/tutorial/tutorial3.htm
trunk/docs/tutorial/tutorial4.htm
Log:
added flow-control, if-elif-else to tutorial
Modified: trunk/docs/tutorial/index.htm
===================================================================
--- trunk/docs/tutorial/index.htm 2004-05-14 07:50:59 UTC (rev 484)
+++ trunk/docs/tutorial/index.htm 2004-05-14 18:02:22 UTC (rev 485)
@@ -54,71 +54,85 @@
<li><a href="tutorial1.htm#toption">The -t Option</a>
</ul>
</ul>
-
- <li>2. <a href="tutorial2.htm#intro">Introduction to Prothon</a>
- <ul>
- <li><a href="tutorial2.htm#comments">2.1 Comments</a>
- <ul>
- <li><a href="tutorial2.htm#hash">Hash symbol</a>
- <li><a href="tutorial2.htm#cstyle">C-style</a>
- </ul>
- <li><a href="tutorial2.htm#indrules">2.2 Indentation</a>
- <ul>
- <li><a href="tutorial2.htm">Indent Rule</a>
- <li><a href="tutorial2.htm#spctabs">Mixing Spaces and Tabs</a>
- </ul>
- <li><a href="tutorial2.htm#linecont">2.3 Line Continuations</a>
- <ul>
- <li><a href="tutorial2.htm#backslash">Backslash</a>
- <li><a href="tutorial2.htm#parens">Open Parentheses</a>
- <li><a href="tutorial2.htm#xtraind">Extra Indents</a>
- </ul>
- <li><a href="tutorial2.htm#dtva">2.4 Data Types, Variables, and Assignment</a>
- <ul>
- <li><a href="tutorial2.htm#dtva">Data Types</a>
- <li><a href="tutorial2.htm#mixtype">Mixed Types</a>
- <li><a href="tutorial2.htm#varass">Assignment</a>
- </ul>
- <li><a href="tutorial3.htm#numeric">2.5 Numeric Data Types</a>
- <ul>
- <li><a href="tutorial3.htm#ints">Integers</a>
- <li><a href="tutorial3.htm#floats">Floats</a>
- </ul>
- <li><a href="tutorial3.htm#strings">2.6 Strings</a>
- <ul>
- <li><a href="tutorial3.htm#quotes">Quotes</a>
- <li><a href="tutorial3.htm#escapes">Escape Sequences</a>
- <li><a href="tutorial3.htm#types">R and X Strings</a>
- <li><a href="tutorial3.htm#triple">Triple Quote Strings</a>
- <li><a href="tutorial3.htm#concat">Concatenation</a>
- <li><a href="tutorial3.htm#index"> Indexing</a>
- <li><a href="tutorial3.htm#slices">Slices</a>
- <li><a href="tutorial3.htm#negnum">Negative Numbers</a>
- <li><a href="tutorial3.htm#defind"> Default Indexes</a>
- <li><a href="tutorial3.htm#strfunc">String Functions</a>
- </ul>
- <li><a href="tutorial4.htm#lists">2.7 Lists</a>
- <ul>
- <li><a href="tutorial4.htm#entlist">Entering a List</a>
- <li><a href="tutorial4.htm#indlist">List Indexing</a>
- <li><a href="tutorial4.htm#mutlist">Mutability</a>
- <li><a href="tutorial4.htm#listassign">Assignment and del</a>
- <li><a href="tutorial4.htm#listfunc">List Functions and !</a>
- </ul>
- <li><a href="tutorial4.htm#tuples">2.8 Tuples</a>
- <ul>
- <li><a href="tutorial4.htm#tucr">Entering a Tuple</a>
- <li><a href="tutorial4.htm#tufun">Functions</a>
- </ul>
- <li><a href="tutorial4.htm#dicts">2.9 Dictionaries</a>
- <ul>
- <li><a href="tutorial4.htm#keyval">Keys and Values</a>
- <li><a href="tutorial4.htm#keyrules">Rules about Keys</a>
- <li><a href="tutorial4.htm#dictenter">Entering a Dictionary</a>
- <li><a href="tutorial4.htm#dictmutable">Assignment and del</a>
- <li><a href="tutorial4.htm#mutlist">Dictionary Functions and !</a>
- </ul>
- </ul>
+ <li>2. <a href="tutorial2.htm#intro">Introduction to Prothon</a>
+ <ul>
+ <li><a href="tutorial2.htm#comments">2.1 Comments</a>
+ <ul>
+ <li><a href="tutorial2.htm#hash">Hash symbol</a>
+ <li><a href="tutorial2.htm#cstyle">C-style</a>
+ </ul>
+ <li><a href="tutorial2.htm#indrules">2.2 Indentation</a>
+ <ul>
+ <li><a href="tutorial2.htm">Indent Rule</a>
+ <li><a href="tutorial2.htm#spctabs">Mixing Spaces and Tabs</a>
+ </ul>
+ <li><a href="tutorial2.htm#linecont">2.3 Line Continuations</a>
+ <ul>
+ <li><a href="tutorial2.htm#backslash">Backslash</a>
+ <li><a href="tutorial2.htm#parens">Open Parentheses</a>
+ <li><a href="tutorial2.htm#xtraind">Extra Indents</a>
+ </ul>
+ </ul>
+ <li>3. <a href="tutorial3.htm#dtva">Data Types, Variables, and Assignment</a>
+ <ul>
+ <li><a href="tutorial3.htm#dtva">3.1 Objects, Types & Containers</a>
+ <ul>
+ <li><a href="tutorial3.htm#datatypes">Data Types</a>
+ <li><a href="tutorial3.htm#mixtype">Mixed Types</a>
+ <li><a href="tutorial3.htm#varass">Assignment</a>
+ </ul>
+ <li><a href="tutorial3.htm#numeric">3.2 Numeric Types</a>
+ <ul>
+ <li><a href="tutorial3.htm#ints">Integers</a>
+ <li><a href="tutorial3.htm#floats">Floats</a>
+ </ul>
+ <li><a href="tutorial3.htm#strings">3.3 Strings</a>
+ <ul>
+ <li><a href="tutorial3.htm#quotes">Quotes</a>
+ <li><a href="tutorial3.htm#escapes">Escape Sequences</a>
+ <li><a href="tutorial3.htm#types">R and X Strings</a>
+ <li><a href="tutorial3.htm#triple">Triple Quote Strings</a>
+ <li><a href="tutorial3.htm#concat">Concatenation</a>
+ <li><a href="tutorial3.htm#index"> Indexing</a>
+ <li><a href="tutorial3.htm#slices">Slices</a>
+ <li><a href="tutorial3.htm#negnum">Negative Numbers</a>
+ <li><a href="tutorial3.htm#defind"> Default Indexes</a>
+ <li><a href="tutorial3.htm#strfunc">String Functions</a>
+ </ul>
+ <li><a href="tutorial4.htm#lists">3.4 Lists</a>
+ <ul>
+ <li><a href="tutorial4.htm#entlist">Entering a List</a>
+ <li><a href="tutorial4.htm#indlist">List Indexing</a>
+ <li><a href="tutorial4.htm#mutlist">Mutability</a>
+ <li><a href="tutorial4.htm#listassign">Assignment and del</a>
+ <li><a href="tutorial4.htm#listfunc">List Functions and !</a>
+ </ul>
+ <li><a href="tutorial4.htm#tuples">3.5 Tuples</a>
+ <ul>
+ <li><a href="tutorial4.htm#tucr">Entering a Tuple</a>
+ <li><a href="tutorial4.htm#tufun">Functions</a>
+ </ul>
+ <li><a href="tutorial4.htm#dicts">3.6 Dictionaries</a>
+ <ul>
+ <li><a href="tutorial4.htm#keyval">Keys and Values</a>
+ <li><a href="tutorial4.htm#keyrules">Rules about Keys</a>
+ <li><a href="tutorial4.htm#dictenter">Entering a Dictionary</a>
+ <li><a href="tutorial4.htm#dictmutable">Assignment and del</a>
+ <li><a href="tutorial4.htm#mutlist">Dictionary Functions and
+ !</a>
+ </ul>
+ </ul>
+ <li>4. <a href="tutorial5.htm#flowcntrl">Flow Control</a>
+ <ul>
+ <li><a href="tutorial5.htm#if-then-else">4.1 If-Elif-Else</a>
+ <ul>
+ <li><a href="tutorial5.htm#truefalse">True & False</a>
+ <li><a href="tutorial5.htm#bool">obj.bool_?</a>
+ <li><a href="tutorial5.htm#smplcode">Sample Code</a>
+ </ul>
+
+ </ul>
+ </ul>
</td>
</tr>
</table>
Modified: trunk/docs/tutorial/tutorial2.htm
===================================================================
--- trunk/docs/tutorial/tutorial2.htm 2004-05-14 07:50:59 UTC (rev 484)
+++ trunk/docs/tutorial/tutorial2.htm 2004-05-14 18:02:22 UTC (rev 485)
@@ -32,7 +32,7 @@
<br>
<table width="630" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffee" height="1707">
<tr>
- <td height="2329" valign="top">
+ <td height="1506" valign="top">
<p align="left"><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="intro"></a>2.0
Introduction to Prothon</font></p>
<p align="left"><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="comments"></a>2.1
@@ -111,58 +111,7 @@
indents you must tab in at least once before using spaces for alignment:</p>
<pre>x = factor(a,b)+
factor(c,d)</pre>
- <p><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="dtva"></a>2.4
- Data Types, Variables and Assignments</font> </p>
- <p>You've already seen variables and assignment, but let's look at them
- more closely. In Prothon everything is an object. You will hear this
- over and over. Objects are actually quite simple but we will learn about
- them slowly as we go through this tutorial. For now we will learn that
- an object can hold data. Ordinary binary computer data of ones, zeros,
- bytes, characters, etc. </p>
- <p><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="dtva"></a></font>Prothon
- makes it wasy for you to use an object with simple data types like integers
- and strings. Unlike some languages these types are not special. You
- can create your own types like these. For now we will just use them
- and now worry about where they come from. Some of the most basic types
- to use are the Integer, Float, and String objects:</p>
- <pre>
->>> 5 + 4 # integer addition
-9
->>> 1.5 * 4.0 # floating point multiplication
-6
->>> "Hello " + "World" # string concatenation
-Hello World
->>></pre>
- <p><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="mixtype"></a></font>You
- can also mix types sometimes. The rules for when types can be mixed
- is up to the definition of the type itself:</p>
- <pre>>>> 1.3 * 2
-2.6
->>> "hello " + 33
-hello 33
->>></pre>
- <p><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="varass"></a></font>Variables
- are labeled containers, such as "x", that hold objects. You
- put an object into a variable using an assignment statement such as
- "x = 3". Then later you can use the variable in the place
- of the constant object 3. Note that you can have multiple items assigned
- at once, which is very useful for swapping items:</p>
- <pre>>> x, y = 1, 2
-1
->>> print x, y
-1 2
->>> x, y = y, x
-2
->>> print x, y
-2 1
->>></pre>
- <p>You may also assign the same value to multiple destinations in one
- statement:</p>
- <pre>>>> x = y = 99
-99
->>> print x, y
-99 99
->>></pre>
+ <p> </p>
</td>
</tr>
</table>
Modified: trunk/docs/tutorial/tutorial3.htm
===================================================================
--- trunk/docs/tutorial/tutorial3.htm 2004-05-14 07:50:59 UTC (rev 484)
+++ trunk/docs/tutorial/tutorial3.htm 2004-05-14 18:02:22 UTC (rev 485)
@@ -1,6 +1,6 @@
<html>
<head>
-<title>Prothon Tutorial - 2.5</title>
+<title>Prothon Tutorial - 3.0</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
@@ -33,8 +33,62 @@
<table width="630" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffee" height="1707">
<tr>
<td height="2265" valign="top">
- <p align="left"><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="numeric"></a>2.5
- Numeric Data Types</font></p>
+ <p><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="dtva"></a>3.0
+ Data Types, Variables and Assignments</font> </p>
+ <p><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="dtva"></a>3.1
+ Objects, Types, & Containers</font></p>
+ <p>You've already seen variables and assignment, but let's look at them
+ more closely. In Prothon everything is an object. You will hear this
+ over and over. Objects are actually quite simple but we will learn about
+ them slowly as we go through this tutorial. For now we will learn that
+ an object can hold data. Ordinary binary computer data of ones, zeros,
+ bytes, characters, etc. </p>
+ <p><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="datatypes"></a></font>Prothon
+ makes it wasy for you to use an object with simple data types like integers
+ and strings. Unlike some languages these types are not special. You
+ can create your own types like these. For now we will just use them
+ and now worry about where they come from. Some of the most basic types
+ to use are the Integer, Float, and String objects:</p>
+ <pre>
+>>> 5 + 4 # integer addition
+9
+>>> 1.5 * 4.0 # floating point multiplication
+6
+>>> "Hello " + "World" # string concatenation
+Hello World
+>>></pre>
+ <p><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="mixtype"></a></font>You
+ can also mix types sometimes. The rules for when types can be mixed
+ is up to the definition of the type itself:</p>
+ <pre>>>> 1.3 * 2
+2.6
+>>> "hello " + 33
+hello 33
+>>></pre>
+ <p><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="varass"></a></font>Variables
+ are labeled containers, such as "x", that hold objects. You
+ put an object into a variable using an assignment statement such as
+ "x = 3". Then later you can use the variable in the place
+ of the constant object 3. Note that you can have multiple items assigned
+ at once, which is very useful for swapping items:</p>
+ <pre>>> x, y = 1, 2
+1
+>>> print x, y
+1 2
+>>> x, y = y, x
+2
+>>> print x, y
+2 1
+>>></pre>
+ <p>You may also assign the same value to multiple destinations in one
+ statement:</p>
+ <pre>>>> x = y = 99
+99
+>>> print x, y
+99 99
+>>></pre>
+ <p align="left"><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="numeric"></a>3.2
+ Numeric Types</font></p>
<p align="left"><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="ints"></a></font>Prothon
integers are 64-bit, signed numbers. Using 64-bit integers eliminates
the need for having a special "long" type to have larger ints
@@ -62,7 +116,7 @@
<pre>>>> print 1/3, 1.1, -1.1, 1e3, 1.1E22, 1e-1, -1e1, -1e-1
.333333 1.1 -1.1 1000 1.1e+22 .1 -10 -.1
>>></pre>
- <p><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="strings"></a>2.6
+ <p><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="strings"></a>3.3
Strings</font></p>
<p>Strings are a powerful data type in Prothon. Unlike many languages,
they can be of unlimited size (constrained only by memory size) and
Modified: trunk/docs/tutorial/tutorial4.htm
===================================================================
--- trunk/docs/tutorial/tutorial4.htm 2004-05-14 07:50:59 UTC (rev 484)
+++ trunk/docs/tutorial/tutorial4.htm 2004-05-14 18:02:22 UTC (rev 485)
@@ -33,7 +33,7 @@
<table width="630" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffee" height="1707">
<tr>
<td height="3521" valign="top">
- <p align="left"><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="lists"></a>2.7
+ <p align="left"><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="lists"></a>3.4
Lists</font></p>
<p align="left"><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="entlist"></a></font>A
Prothon list is a sequential list of objects. Each object can be of
@@ -137,7 +137,7 @@
>>> list.reverse!()
[6, 4, 3, 2, 1, 0]
>>></pre>
- <p><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="tuples"></a>2.8
+ <p><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="tuples"></a>3.5
Tuples</font> </p>
<p>Tuples are almost exactly like lists except for one big difference.
They are immutable. This means you cannot change the items in a tuple
@@ -173,7 +173,7 @@
>>> tuple.index(2)
1
>>></pre>
- <p><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="dicts"></a>2.9
+ <p><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="dicts"></a>3.6
Dictionaries</font> </p>
<p><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="keyval"></a></font>A
dictionary is a mutable (changeable) collection of objects like the
Added: trunk/docs/tutorial/tutorial5.htm
===================================================================
--- trunk/docs/tutorial/tutorial5.htm 2004-05-14 07:50:59 UTC (rev 484)
+++ trunk/docs/tutorial/tutorial5.htm 2004-05-14 18:02:22 UTC (rev 485)
@@ -0,0 +1,123 @@
+<html>
+<head>
+<title>Prothon Tutorial - 2.7</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+</head>
+
+<body bgcolor="#FFFFFF" text="#000000">
+<div align="center">
+ <table width="630" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFCC">
+ <tr>
+ <td height="121" width="109"><img src="../images/logo_left.jpg" width="109" height="135"></td>
+ <td valign="center" height="43">
+ <div align="center"><font size="5" face="Verdana, Arial, Helvetica, sans-serif">Prothon
+ Tutorial</font></div>
+ </td>
+ <td valign="center" height="121" width="106"><img src="../images/logo_right.jpg" width="109" height="135"></td>
+ </tr>
+ </table>
+ <br>
+ <table width="630" border="0" cellpadding="0" cellspacing="0">
+ <tr>
+ <td width="114" height="25" valign="top"> <a href="http://prothon.org">Prothon
+ Home</a></td>
+ <td width="194" valign="middle" align="center" height="25"><a href="tutorial3.htm">Previous
+ Page</a></td>
+ <td width="183" valign="middle" align="center" height="25"><a href="index.htm">Tutorial
+ Outline</a></td>
+ <td width="139" valign="middle" align="center" height="25"><a href="index.htm">Next
+ Page</a></td>
+ </tr>
+ </table>
+ <br>
+ <table width="630" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffee" height="1707">
+ <tr>
+ <td height="3521" valign="top">
+ <p align="left"><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="flowcntrl"></a>4.0
+ Flow Control</font></p>
+ <p align="left"><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="if-then-else"></a>4.1
+ If-Elif-Else</font></p>
+ <p align="left">The if, elif, and else statements provide the ability
+ to selectively control which Prothon statements get executed and which
+ don't. They do this by evaluating an expression and based on the results
+ they conditionally execute code blocks.</p>
+ <p align="left"><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="truefalse"></a></font>The
+ particular expressions used by the if-elif-else statements aways result
+ in one of two particular exact objects. One is the "True"
+ object and one is the "False" object. These objects are special
+ one-of-a-kind objects that are different from types like integers and
+ strings. They do not hold a data value, they just exist. </p>
+ <p align="left"><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="ques"></a></font>You
+ might be wondering how expressions can result in these exact objects.
+ The answer is that there are many functions that are special that return
+ only these "True" or "False" objects. These functions
+ all have names that end in a question mark like the dictionary function
+ dict.hasKey_?(key). This returns True if the dictionary has the key
+ and False if it doesn't. If you write a "question" function
+ that always returns only True or False, then you should end the name
+ in a question mark also.</p>
+ <p align="left"><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="bool"></a></font>There
+ is one very special function called obj.bool_?() that can be called
+ on any object of any type and that type decides whether that object
+ should be considered True or False. For example, the numeric types consider
+ the number zero to be false and all other numbers to be True (just like
+ the C language). Likewise, lists and strings are considered False is
+ they are empty and True otherwise. Each type can conveniently define
+ what is True or False for it's type.</p>
+ <p><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="smplcode"></a></font>Let's
+ look at how you use the if-elif-else statement. This example shows the
+ different parts of the statement. The "if" expression is always
+ tested. If its expression returns true then its block is executed and
+ all the other parts are skipped over. The "elif" expression
+ is evaluated if all the expressions before return False and then its
+ block is executed if it returns True just like the "if". The
+ "else" block is executed if all expression before return false.</p>
+ <pre># Prothon source file tut4.pr
+
+if True:
+ print "Hello World"
+
+if False:
+ print "I'm invisible"
+
+if False:
+ print 'not this one'
+else:
+ print 'This is the one'
+
+if 0:
+ print 'not 0, it is false'
+elif "":
+ print 'not "", it is false also'
+elif []:
+ print 'not [] either'
+else:
+ print 'All the others are false, so I'm the one'
+
+if 'x'+"abc":
+ if 7**3:
+ print "Many things are true"</pre>
+ <p>Here is the output of running the file tut4.pr above: </p>
+ <pre>Hello World
+False is the one
+XXX
+Many things are true
+</pre>
+ </td>
+ </tr>
+ </table>
+ <table width="630" border="0" cellpadding="0" cellspacing="0">
+ <tr>
+ <td width="114" height="25" valign="top"> <a href="http://prothon.org">Prothon
+ Home</a></td>
+ <td width="194" valign="middle" align="center" height="25"><a href="tutorial3.htm">Previous
+ Page</a></td>
+ <td width="183" valign="middle" align="center" height="25"><a href="index.htm">Tutorial
+ Outline</a></td>
+ <td width="139" valign="middle" align="center" height="25"><a href="index.htm">Next
+ Page</a></td>
+ </tr>
+ </table>
+</div>
+</body>
+</html>