rev 481 - trunk/docs/tutorial
SVN User <[email protected]> Thu, 13 May 2004 23:18:28 -0400
| Newsgroups | gmane.comp.lang.prothon.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: mark
Date: 2004-05-13 23:18:24 -0400 (Thu, 13 May 2004)
New Revision: 481
Added:
trunk/docs/tutorial/tutorial3.htm
Modified:
trunk/docs/tutorial/index.htm
trunk/docs/tutorial/tutorial2.htm
Log:
added strings to tutorial
Modified: trunk/docs/tutorial/index.htm
===================================================================
--- trunk/docs/tutorial/index.htm 2004-05-13 23:53:14 UTC (rev 480)
+++ trunk/docs/tutorial/index.htm 2004-05-14 03:18:24 UTC (rev 481)
@@ -63,8 +63,8 @@
</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>
+ <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>
@@ -76,9 +76,26 @@
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>
+ <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>
+ </ul>
</ul>
</ul>
Modified: trunk/docs/tutorial/tutorial2.htm
===================================================================
--- trunk/docs/tutorial/tutorial2.htm 2004-05-13 23:53:14 UTC (rev 480)
+++ trunk/docs/tutorial/tutorial2.htm 2004-05-14 03:18:24 UTC (rev 481)
@@ -32,7 +32,7 @@
<br>
<table width="630" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffee" height="1707">
<tr>
- <td height="2286" valign="top">
+ <td height="2329" 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
@@ -147,15 +147,22 @@
"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
+ <pre>>> x, y = 1, 2
1
->>> print x,y
+>>> print x, y
1 2
->>> x,y = y,x
+>>> x, y = y, x
2
->>> print x,y
+>>> 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>
</td>
</tr>
</table>
Added: trunk/docs/tutorial/tutorial3.htm
===================================================================
--- trunk/docs/tutorial/tutorial3.htm 2004-05-13 23:53:14 UTC (rev 480)
+++ trunk/docs/tutorial/tutorial3.htm 2004-05-14 03:18:24 UTC (rev 481)
@@ -0,0 +1,166 @@
+<html>
+<head>
+<title>Prothon Tutorial - 2.5</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="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="tutorial2.htm">Next
+ Page</a></td>
+ </tr>
+ </table>
+ <br>
+ <table width="630" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffee" height="1707">
+ <tr>
+ <td height="2286" 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 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
+ or having a unsigned type. Integer constants may be entered into Prothon
+ code in several ways. The _ symbol in the number is just a comment to
+ help read the number. The number starting with a zero is in octal and
+ the numbers starting with 0x are hexadecimal. The last number is the
+ largest positive number:</p>
+ <pre>>> print 1, -1, 1_000_000, 010, 0x1000, 0x7fff_ffff_ffff_ffff
+1 -1 1000000 8 4096 9223372036854775807
+>>></pre>
+ <p><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="floats"></a></font>Floating
+ point numbers are standard "C double" 64-bit IEEE floating
+ point numbers. You can tell a floating point number from an integer
+ by the presence of a decimal point, such as in "1.0" or the
+ exponent symbol "e" and in "1e3".. </p>
+ <p>Most standard representations of floating point or scientific numbers
+ will work in Prothon with one exception. That exception is that the
+ number may not end in a period. When you type a number that ends in
+ the decimal point add a zero, I.E. change "1." to "1.0".
+ </p>
+ <p>Note that unlike many languages, when you divide two integers, you
+ get a floating point number (unless you use a special // symbol which
+ will be explained later).</p>
+ <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
+ 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
+ can hold any arbitrary data, even binary data such as photos and movies.They
+ are of course also good for their traditional role of storing and manipulating
+ text.</p>
+ <p><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="quotes"></a></font>The
+ string can be entered in many forms. The two most common are as ascii
+ characters surrounded by either single or double quotes. There is no
+ difference if you use single or double quotes, except that using one
+ makes it easier to include the other type inside the string:</p>
+ <pre>>>> "It's my turn"
+It's my turn
+>>> '"Hello World"'
+"Hello World"
+>>></pre>
+ <p><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="escapes"></a></font>If
+ you need to use the same kind of quote inside the string you need to
+ use an escape sequence. Escape sequences start with a backslash. If
+ you wish to place a double quote inside a string made of double quotes
+ then you insert a \" sequence. Similarly a \' will insert a single
+ quote. Some other escape sequences are:</p>
+ <pre>
+ \n new line
+ \t tab
+ \\ backslash character
+ \nnn octal value char
+ \xNN hex value char</pre>
+ <p><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="types"></a></font>There
+ are a number of special types of strings. If you prefix a string with
+ the letter r as in r"xxx", then escape sequences are not converted.
+ If you start it with the letter x, then it is a special string for inputting
+ binary data in hex form where only hex chars, white space and newlines
+ are allowed:</p>
+ <pre>>>> r' \n '
+ \n
+>>> x' 31 32 33 '
+123
+>>></pre>
+ <p><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="triple"></a></font>One
+ last type of string is useful for entering multiple lines of text. You
+ use three quotes instead of one and it will include line endings.</p>
+ <pre>x = """ line 1
+ line 2 """</pre>
+ <p><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="concat"></a></font>Strings
+ can be added together (concatenated) just like numbers. You can actually
+ add a string on the left to anything on the right and Prothon will convert
+ the item on the right to it's string value before the addition:</p>
+ <pre>>>> "abc" + "def"
+abcdef
+>>> "The number is " + 99
+The number is 99
+>>></pre>
+ <p><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="index"></a></font>You
+ can access the individual characters in a string by the indexing operator
+ "xxx"[n] where n specifies the char to be extracted. The chars
+ are numbered with the first char as zero. So "abc"[1] evaluates
+ to the string "b". </p>
+ <p><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="slices"></a></font>You
+ can also access slices of more than one char by using the form [m:n]
+ where m specifies the index of the first char and n is one greater than
+ the index of the last character. You can also add a third number to
+ specify a step size to get non-contiguous characters:</p>
+ <pre>>>> x = "abcdefghijklm"
+abcdefghijklm
+>>> print x[2], x[1:3], x[0:10:2], x[12:-1:-1]
+XXX</pre>
+ <p><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="negnum"></a></font>If
+ you use a negative number for an index, it is treated as an offset from
+ the end of the string. The number -1 will index the last character in
+ the string, -2 will access the next to last, etc. One way to think of
+ this is that the index points to the left side of the char and that
+ zero points to the left of the first char and the right of the last
+ char.</p>
+ <p><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="defind"></a></font>One
+ last trick to use with indexes is to leave the number out and use the
+ defaults. The first index will default to the leftmost char if the third
+ is positive and to the rightmost position if the third is negative.
+ The second will default to the opposite end of the string from the first:</p>
+ <pre>>>> x = "abcdef"
+abcdef
+>>> print x[-2], x[-3:-1], x[3:], x[:2], x[:2:-1], x[-1:-1:-1], x[:]
+XXX</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="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
+ Page</a></td>
+ </tr>
+ </table>
+</div>
+</body>
+</html>