rev 480 - trunk/docs/tutorial
SVN User <[email protected]> Thu, 13 May 2004 19:53:18 -0400
| Newsgroups | gmane.comp.lang.prothon.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: mark
Date: 2004-05-13 19:53:14 -0400 (Thu, 13 May 2004)
New Revision: 480
Modified:
trunk/docs/tutorial/index.htm
trunk/docs/tutorial/tutorial1.htm
trunk/docs/tutorial/tutorial2.htm
Log:
finished section 2 of tutorial
Modified: trunk/docs/tutorial/index.htm
===================================================================
--- trunk/docs/tutorial/index.htm 2004-05-13 21:31:05 UTC (rev 479)
+++ trunk/docs/tutorial/index.htm 2004-05-13 23:53:14 UTC (rev 480)
@@ -22,7 +22,7 @@
<br>
<table width="630" border="0" cellpadding="0" cellspacing="0">
<tr>
- <td width="114" height="25" valign="top"> <a href="../index.html">Prothon
+ <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">Previous Page</td>
<td width="183" valign="middle" align="center" height="25">Tutorial Outline</td>
@@ -34,240 +34,61 @@
<table width="630" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffee" height="1707">
<tr>
<td height="2203" valign="top">
- <UL CLASS="TofC">
- <LI>1. <a href="tutorial1.htm#uint">Using the Prothon Interpreter</a>
- <UL>
- <LI><A href="tutorial1.htm#intcon">1.1 Interactive Console </a>
- <UL>
- <LI><A href="tutorial1.htm#com">Command-Line Options</a>
- <LI><A href="tutorial1.htm#calculator">Calculator</a>
- <LI><a href="tutorial1.htm#indent"><u>Indenting</u></a>
+ <ul class="TofC">
+ <li>1. <a href="tutorial1.htm#uint">Using the Prothon Interpreter</a>
+ <ul>
+ <li><a href="tutorial1.htm#intcon">1.1 Interactive Console </a>
+ <ul>
+ <li><a href="tutorial1.htm#com">Command-Line Options</a>
+ <li><a href="tutorial1.htm#calculator">Calculator</a>
+ <li><a href="tutorial1.htm#indent"><u>Indenting</u></a>
</ul>
- <LI><A href="tutorial1.htm#eapf">1.2 Executing A Prothon File</a>
- <UL>
- <LI><A href="tutorial1.htm#eapf">Line Endings</a>
- <LI><a href="tutorial1.htm#args">Arguments</a>
+ <li><a href="tutorial1.htm#eapf">1.2 Executing A Prothon File</a>
+ <ul>
+ <li><a href="tutorial1.htm#eapf">Line Endings</a>
+ <li><a href="tutorial1.htm#args">Arguments</a>
</ul>
- <LI><A href="tutorial1.htm#confile">1.3 Using Console With Files</a>
- <UL>
- <LI><A href="tutorial1.htm#ioption">The -i Option</a>
- <LI><a href="tutorial1.htm#toption">The -t Option</a>
+ <li><a href="tutorial1.htm#confile">1.3 Using Console With Files</a>
+ <ul>
+ <li><a href="tutorial1.htm#ioption">The -i Option</a>
+ <li><a href="tutorial1.htm#toption">The -t Option</a>
</ul>
-
</ul>
- </ul>
-
- </td>
- </tr>
- </table>
- <table width="630" border="0" cellpadding="0" cellspacing="0">
- <tr>
- <td width="114" height="25" valign="top"> <a href="../index.html">Prothon
- Home</a></td>
- <td width="194" valign="middle" align="center" height="25">Previous Page</td>
- <td width="183" valign="middle" align="center" height="25">Tutorial Outline</td>
- <td width="139" valign="middle" align="center" height="25"><a href="tutorial1.htm">Next
- Page</a></td>
- </tr>
- </table>
-</div>
-
-href="node6.html#SECTION006200000000000000000">4.2 for Statements
- <LI><A href="node6.html#SECTION006300000000000000000">4.3 The range()
- Function</a>
- <LI><A href="node6.html#SECTION006400000000000000000">4.4 break
- and continue Statements, and else Clauses on Loops</a>
- <LI><A href="node6.html#SECTION006500000000000000000">4.5 pass Statements</a>
- <LI><A href="node6.html#SECTION006600000000000000000">4.6 Defining
- Functions</a>
- <LI><A href="node6.html#SECTION006700000000000000000">4.7 More on
- Defining Functions</a>
- <UL>
- <LI><A href="node6.html#SECTION006710000000000000000">4.7.1
- Default Argument Values</a>
- <LI><A href="node6.html#SECTION006720000000000000000">4.7.2
- Keyword Arguments</a>
- <LI><A href="node6.html#SECTION006730000000000000000">4.7.3
- Arbitrary Argument Lists</a>
- <LI><A href="node6.html#SECTION006740000000000000000">4.7.4
- Unpacking Argument Lists</a>
- <LI><A href="node6.html#SECTION006750000000000000000">4.7.5
- Lambda Forms</a>
- <LI><A href="node6.html#SECTION006760000000000000000">4.7.6
- Documentation Strings</a>
+ <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="node7.html">5. Data Structures</a>
- <UL>
- <LI><A href="node7.html#SECTION007100000000000000000">5.1 More on
- Lists</a>
- <UL>
- <LI><A href="node7.html#SECTION007110000000000000000">5.1.1
- Using Lists as Stacks</a>
- <LI><A href="node7.html#SECTION007120000000000000000">5.1.2
- Using Lists as Queues</a>
- <LI><A href="node7.html#SECTION007130000000000000000">5.1.3
- Functional Programming Tools</a>
- <LI><A href="node7.html#SECTION007140000000000000000">5.1.4
- List Comprehensions</a>
+ <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="node7.html#SECTION007200000000000000000">5.2 The del
- statement</a>
- <LI><A href="node7.html#SECTION007300000000000000000">5.3 Tuples
- and Sequences</a>
- <LI><A href="node7.html#SECTION007400000000000000000">5.4 Dictionaries</a>
- <LI><A href="node7.html#SECTION007500000000000000000">5.5 Looping
- Techniques</a>
- <LI><A href="node7.html#SECTION007600000000000000000">5.6 More on
- Conditions</a>
- <LI><A href="node7.html#SECTION007700000000000000000">5.7 Comparing
- Sequences and Other Types</a>
- </ul>
- <LI><A href="node8.html">6. Modules</a>
- <UL>
- <LI><A href="node8.html#SECTION008100000000000000000">6.1 More on
- Modules</a>
- <UL>
- <LI><A href="node8.html#SECTION008110000000000000000">6.1.1
- The Module Search Path</a>
- <LI><A href="node8.html#SECTION008120000000000000000">6.1.2
- ``Compiled'' Python files</a>
+ <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="node8.html#SECTION008200000000000000000">6.2 Standard
- Modules</a>
- <LI><A href="node8.html#SECTION008300000000000000000">6.3 The dir()
- Function</a>
- <LI><A href="node8.html#SECTION008400000000000000000">6.4 Packages</a>
- <UL>
- <LI><A href="node8.html#SECTION008410000000000000000">6.4.1
- Importing * From a Package</a>
- <LI><A href="node8.html#SECTION008420000000000000000">6.4.2
- Intra-package References</a>
- <LI><A href="node8.html#SECTION008430000000000000000">6.4.3
- Packages in Multiple Directories</a>
+ <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>
+
</ul>
- <LI><A href="node9.html">7. Input and Output</a>
- <UL>
- <LI><A href="node9.html#SECTION009100000000000000000">7.1 Fancier
- Output Formatting</a>
- <LI><A href="node9.html#SECTION009200000000000000000">7.2 Reading
- and Writing Files</a>
- <UL>
- <LI><A href="node9.html#SECTION009210000000000000000">7.2.1
- Methods of File Objects</a>
- <LI><A href="node9.html#SECTION009220000000000000000">7.2.2
- The pickle Module</a>
- </ul>
- </ul>
- <LI><A href="node10.html">8. Errors and Exceptions</a>
- <UL>
- <LI><A href="node10.html#SECTION0010100000000000000000">8.1 Syntax
- Errors</a>
- <LI><A href="node10.html#SECTION0010200000000000000000">8.2 Exceptions</a>
- <LI><A href="node10.html#SECTION0010300000000000000000">8.3 Handling
- Exceptions</a>
- <LI><A href="node10.html#SECTION0010400000000000000000">8.4 Raising
- Exceptions</a>
- <LI><A href="node10.html#SECTION0010500000000000000000">8.5 User-defined
- Exceptions</a>
- <LI><A href="node10.html#SECTION0010600000000000000000">8.6 Defining
- Clean-up Actions</a>
- </ul>
- <LI><A href="node11.html">9. Classes</a>
- <UL>
- <LI><A href="node11.html#SECTION0011100000000000000000">9.1 A Word
- About Terminology</a>
- <LI><A href="node11.html#SECTION0011200000000000000000">9.2 Python
- Scopes and Name Spaces</a>
- <LI><A href="node11.html#SECTION0011300000000000000000">9.3 A First
- Look at Classes</a>
- <UL>
- <LI><A href="node11.html#SECTION0011310000000000000000">9.3.1
- Class Definition Syntax</a>
- <LI><A href="node11.html#SECTION0011320000000000000000">9.3.2
- Class Objects</a>
- <LI><A href="node11.html#SECTION0011330000000000000000">9.3.3
- Instance Objects</a>
- <LI><A href="node11.html#SECTION0011340000000000000000">9.3.4
- Method Objects</a>
- </ul>
- <LI><A href="node11.html#SECTION0011400000000000000000">9.4 Random
- Remarks</a>
- <LI><A href="node11.html#SECTION0011500000000000000000">9.5 Inheritance</a>
- <UL>
- <LI><A href="node11.html#SECTION0011510000000000000000">9.5.1
- Multiple Inheritance</a>
- </ul>
- <LI><A href="node11.html#SECTION0011600000000000000000">9.6 Private
- Variables</a>
- <LI><A href="node11.html#SECTION0011700000000000000000">9.7 Odds
- and Ends</a>
- <LI><A href="node11.html#SECTION0011800000000000000000">9.8 Exceptions
- Are Classes Too</a>
- <LI><A href="node11.html#SECTION0011900000000000000000">9.9 Iterators</a>
- <LI><A href="node11.html#SECTION00111000000000000000000">9.10 Generators</a>
- </ul>
- <LI><A href="node12.html">10. Brief Tour of the Standard Library</a>
- <UL>
- <LI><A href="node12.html#SECTION0012100000000000000000">10.1 Operating
- System Interface</a>
- <LI><A href="node12.html#SECTION0012200000000000000000">10.2 File
- Wildcards</a>
- <LI><A href="node12.html#SECTION0012300000000000000000">10.3 Command
- Line Arguments</a>
- <LI><A href="node12.html#SECTION0012400000000000000000">10.4 Error
- Output Redirection and Program Termination</a>
- <LI><A href="node12.html#SECTION0012500000000000000000">10.5 String
- Pattern Matching</a>
- <LI><A href="node12.html#SECTION0012600000000000000000">10.6 Mathematics</a>
- <LI><A href="node12.html#SECTION0012700000000000000000">10.7 Internet
- Access</a>
- <LI><A href="node12.html#SECTION0012800000000000000000">10.8 Dates
- and Times</a>
- <LI><A href="node12.html#SECTION0012900000000000000000">10.9 Data
- Compression</a>
- <LI><A href="node12.html#SECTION00121000000000000000000">10.10 Performance
- Measurement</a>
- <LI><A href="node12.html#SECTION00121100000000000000000">10.11 Quality
- Control</a>
- <LI><A href="node12.html#SECTION00121200000000000000000">10.12 Batteries
- Included</a>
- </ul>
- <LI><A href="node13.html">11. What Now?</a>
- <LI><A href="node14.html">A. Interactive Input Editing and History Substitution</a>
- <UL>
- <LI><A href="node14.html#SECTION0014100000000000000000">A.1 Line
- Editing</a>
- <LI><A href="node14.html#SECTION0014200000000000000000">A.2 History
- Substitution</a>
- <LI><A href="node14.html#SECTION0014300000000000000000">A.3 Key
- Bindings</a>
- <LI><A href="node14.html#SECTION0014400000000000000000">A.4 Commentary</a>
- </ul>
- <LI><A href="node15.html">B. Floating Point Arithmetic: Issues and Limitations</a>
- <UL>
- <LI><A href="node15.html#SECTION0015100000000000000000">B.1 Representation
- Error</a>
- </ul>
- <LI><A href="node16.html">C. History and License</a>
- <UL>
- <LI><A href="node16.html#SECTION0016100000000000000000">C.1 History
- of the software</a>
- <LI><A href="node16.html#SECTION0016200000000000000000">C.2 Terms
- and conditions for accessing or otherwise using Python</a>
- </ul>
- <LI><A href="node17.html">D. Glossary</a>
- <LI><A href="node18.html">Index</a>
- <LI><A href="node19.html">About this document ...</a>
-
+ </ul>
+ </td>
+ </tr>
+ </table>
-
-
-
<table width="630" border="0" cellpadding="0" cellspacing="0">
<tr>
- <td width="114" height="25" valign="top"> <a href="../index.html">Prothon
+ <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">Previous Page</td>
<td width="183" valign="middle" align="center" height="25">Tutorial Outline</td>
@@ -275,7 +96,7 @@
Page</a></td>
</tr>
</table>
-
+ </div>
</body>
</html>
Modified: trunk/docs/tutorial/tutorial1.htm
===================================================================
--- trunk/docs/tutorial/tutorial1.htm 2004-05-13 21:31:05 UTC (rev 479)
+++ trunk/docs/tutorial/tutorial1.htm 2004-05-13 23:53:14 UTC (rev 480)
@@ -19,13 +19,13 @@
<br>
<table width="630" border="0" cellpadding="0" cellspacing="0">
<tr>
- <td width="114" height="25" valign="top"> <a href="../index.html">Prothon
+ <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="index.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="description-2.htm">Next
+ <td width="139" valign="middle" align="center" height="25"><a href="tutorial2.htm">Next
Page</a></td>
</tr>
</table>
@@ -158,13 +158,13 @@
</table>
<table width="630" border="0" cellpadding="0" cellspacing="0">
<tr>
- <td width="114" height="25" valign="top"> <a href="../index.html">Prothon
+ <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="index.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="description-2.htm">Next
+ <td width="139" valign="middle" align="center" height="25"><a href="tutorial2.htm">Next
Page</a></td>
</tr>
</table>
Modified: trunk/docs/tutorial/tutorial2.htm
===================================================================
--- trunk/docs/tutorial/tutorial2.htm 2004-05-13 21:31:05 UTC (rev 479)
+++ trunk/docs/tutorial/tutorial2.htm 2004-05-13 23:53:14 UTC (rev 480)
@@ -19,13 +19,13 @@
<br>
<table width="630" border="0" cellpadding="0" cellspacing="0">
<tr>
- <td width="114" height="25" valign="top"> <a href="../index.html">Prothon
+ <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="index.htm">Previous
+ <td width="194" valign="middle" align="center" height="25"><a href="tutorial1.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="description-2.htm">Next
+ <td width="139" valign="middle" align="center" height="25"><a href="tutorial2.htm">Next
Page</a></td>
</tr>
</table>
@@ -39,9 +39,8 @@
Comments</font></p>
<p><a name="hash"></a>Any line starting with the hash symbol, aka pound-sign
( # ), is a comment line and is ignored by the interpreter. If the hash
- symbol appears in the middle of the line then the rest of the line is
- ignored. (There are certain exceptions which will be discussed in the
- strings section).</p>
+ symbol appears in the middle of the line, then the rest of the line
+ is ignored.</p>
<pre>>>> # print "Hello"
>>> print "hello" #, "world"
hello
@@ -51,15 +50,120 @@
code easily in a file:</p>
<pre>>>> print "hello" /* "there" */ , "world"
hello world
->>></pre>this
+>>></pre>
+ <p><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="indrules"></a>2.2
+ Indentation</font></p>
+
+ <p>Almost all languages have code blocks. These are multiple lines of
+ code that are logically grouped together to be executed as one unit
+ of code. In the C language for example, a code block is surrounded by
+ braces "{" and "}"</p>
+ <pre>/* This is C code, NOT Prothon code*/
+if (x)
+ {
+ do_something();
+ do_more();
+ }</pre>
+ <p>In Prothon (and Python) the braces aren't needed. The indentation that
+ programmers usually use to help show the block structure anyway, is
+ itself the indicator of the blocks. </p>
+ <p><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="indrul"></a></font>The
+ indentation rule is that when a new block is needed, a line will end
+ in a colon. Then the next line, which is the first line of the block,
+ is indented. Each line of that block then must be indented the same
+ amount to show it belongs to that block. </p>
+ <p>Blocks can be nested by having nested indentation, but lines further
+ down that go back to the left again must line up with a line above to
+ show which block it belongs to.</p>
+ <pre># Prothon code
+if x:
+ do_something()
+ do_more()
+ if y:
+ do_even_more() # new nested block
+ do_more() # back to same block</pre>
+ <font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><b><a name="spctabs"></a></b></font><b>Important:
+ Mixing Spaces and Tabs:</b> You may use either spaces or tabs to indent
+ your blocks, but in any one group of nested blocks, you may not intermix
+ spaces and tabs. You will get an error if you do. The reason for this
+ rule is that mixed spaces and tabs would cause the lines to not line up
+ on editors with tab widths set differently.
+ <p><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="linecont"></a>2.3
+ Line Continuations</font> </p>
+ <p>When a Prothon line is too long to fit in your text editor comfortably,
+ you can spread it across two or more lines by coninuing a line of code
+ on the next line. Some of these ways don't work in the console so I'll
+ just show you examples here.</p>
+ <p><a name="backslash"></a>There are three ways to indicate a line continuation.
+ The first is to end a line with the backslash character ( \ ), making
+ sure that it is the very last character. This even works inside a string:</p>
+ <pre>x = "Hello \
+ World"</pre>
+ <p><a name="parens"></a>Another way to continue a line is to end a line
+ while a left parentheses, bracket, or brace: (, [, or {, still does
+ not have it's matching right partner. The interpreter knows the line
+ must be continued until all such characters partner's are matched up:</p>
+ <pre>x = 3 * (5 +
+ 4 + 6)</pre>
+ <p><a name="xtraind"></a>Finally, the last way to continue a line is to
+ indent a line when the previous line does not end in a colon. Note that
+ you must still follow the indent rules, so if you are using tabs for
+ 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>
</td>
</tr>
</table>
<table width="630" border="0" cellpadding="0" cellspacing="0">
<tr>
- <td width="114" height="25" valign="top"> <a href="../index.html">Prothon
+ <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="index.htm">Previous
+ <td width="194" valign="middle" align="center" height="25"><a href="tutorial1.htm">Previous
Page</a></td>
<td width="183" valign="middle" align="center" height="25"><a href="index.htm">Tutorial
Outline</a></td>