[e-cvs] cvs commit: e/doc/elang quick-ref.html

markm@eros.cs.jhu.edu markm@eros.cs.jhu.edu
Thu, 25 Oct 2001 22:48:07 -0400


markm       01/10/25 22:48:07

  Modified:    doc/elang quick-ref.html
  Log:
  quick ref now corresponds to modern E

Revision  Changes    Path
1.30      +208 -153  e/doc/elang/quick-ref.html

Index: quick-ref.html
===================================================================
RCS file: /cvs/e/doc/elang/quick-ref.html,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- quick-ref.html	2001/09/30 23:43:17	1.29
+++ quick-ref.html	2001/10/26 02:48:07	1.30
@@ -49,92 +49,104 @@
       </TABLE>
       <hr>
       <!-- #BeginEditable "LongBody" -->
-      <p>This is intended as a compact representation of frequently-used syntax
-        and frequently-encountered special characteristics of E. The beginning
-        E user may find it a handy reference while experimenting and reading the
-        book; the experienced E programmer may find it handy as a refresher if
-        returning to the language after some time. This reference does not touch
-        quasi-literals, regular expressions, pattern matching, parse trees, VB
-        syntax, bean syntax, or Kernel-E at all.
+      <p>This is intended as a compact representation of frequently-used syntax 
+        and frequently-encountered special characteristics of E. The beginning 
+        E user may find it a handy reference while experimenting and reading the 
+        book; the experienced E programmer may find it handy as a refresher if 
+        returning to the language after some time. This reference does not touch 
+        quasi-literals, regular expressions, pattern matching, parse trees, or 
+        Kernel-E at all. 
       <ul>
-        <li><a href="#Simple">Simple Statements</a>: def, assign, print, add,
-          comment
-        <li><a href="#Flow">Basic Flow</a>: if, while, for, try
+        <li><a href="#Simple">Simple Statements</a>: def, var, assign, print, 
+          add, comment 
+        <li><a href="#Flow">Basic Flow</a>: if, while, for, try 
         <li><a
-        href="#Modules">Modules</a>: Function, Singleton Object, Object Maker,
-          Delegation, Matching
-        <li><a href="#io">Text File I/O</a>
-        <li><a href="#Windowing">Windowed Apps</a>
+        href="#Modules">Modules</a>: Function, Singleton Object, Object Maker, 
+          Delegation, Matching 
+        <li><a href="#io">Text File I/O</a> 
+        <li><a href="#Windowing">Windowed Apps</a> 
         <li><a
-        href="#Structures">Data Structures</a>: Strings, ConstLists, ConstMaps,
-          FlexLists, FlexMaps
-        <li><a href="#Java">Java Interface</a>
-        <li><a href="#Asynch">Asynch Sends</a>
+        href="#Structures">Data Structures</a>: Strings, ConstLists, ConstMaps, 
+          FlexLists, FlexMaps 
+        <li><a href="#Java">Java Interface</a> 
+        <li><a href="#Asynch">Asynch Sends</a> 
         <li><a href="#Remote">Remote Comm</a> </li>
       </ul>
       <hr>
-      <p><a name=Simple><!-- --></a><b>Simple Statements</b>
-      <blockquote>
-        <pre>def a := 2 + 3
-def b := "answer: "
+      <p><a name=Simple>
+        <!-- -->
+        </a><b>Simple Statements</b> 
+      <pre>def a := 2 + 3
+var a2 := 4
+a2 += 1
+def b := &quot;answer: &quot;
 println(b + a)
-<font face="Times New Roman, Times, serif">// Note: the plus sign is interpreted by the object on the left, so b as a string causes
-// plus to mean string concatenation. The statement "</font>b + a<font face="Times New Roman, Times, serif">" creates a
-// concatenated string without explicit conversion; "</font>a + b<font face="Times New Roman, Times, serif">" would fail as it tried to
-// cast string b to an integer for addition to a.
-#  Second form of comment uses # rather than //</font></pre>
-      </blockquote>
+<font face="Times New Roman, Times, serif">// Note: the plus sign is interpreted by the object on the left, so b as a string
+# causes plus to mean string concatenation. The statement &quot;b + a&quot;
+//creates a concatenated string without explicit conversion; &quot;a + b&quot; would fail 
+// as it tried to cast string b to an integer for addition to a.</font>
+</pre>
       <hr>
-      <p><a name=Flow><!-- --></a><b>Basic Flow</b>
+      <p><a name=Flow>
+        <!-- -->
+        </a><b>Basic Flow</b> 
       <table border=1 cellpadding=6>
-        <tbody>
-        <tr>
-          <td>
+        <tr> 
+          <td> 
             <pre>if (a == b) {
     println("match")
 } else {
     println("no match")
 }</pre>
           </td>
-          <td>
+          <td> 
             <pre>while (a &lt; b) {
     a += 1
 }</pre>
           </td>
-          <td>
+        </tr>
+        <tr> 
+          <td> 
+            <pre>try {
+    3 _/ 0
+} catch err {
+    println(&quot;error: &quot; + err)
+} finally {
+    println(&quot;always&quot;)
+}</pre>
+          </td>
+          <td> 
             <pre>for next in 1..3 {
     println(next)
 }</pre>
-          </td>
-          <td>
-            <pre>try {
-    3 _/ 0
-} catch e {
-    println("error: " + e)
+            <pre>for key =&gt; value in map {
+    println(&quot;got pair&quot;)
 }</pre>
           </td>
         </tr>
-        </tbody>
+        <tbody> </tbody> 
       </table>
       <hr>
-      <p><a name=Modules><!-- --></a><b>Modules</b>
+      <p><a name=Modules>
+        <!-- -->
+        </a><b>Modules</b> 
       <table border=1 cellpadding=2>
-        <tbody>
-        <tr>
+        <tbody> 
+        <tr> 
           <td><b>Function</b></td>
           <td><b>Singleton Object (stateless)</b></td>
         </tr>
-        <tr>
-          <td>
+        <tr> 
+          <td> 
             <pre>def addTwoPrint(number) :any {
     println(number + 2)
     number + 2
-    <font face="Times New Roman, Times, serif"># &quot;</font>:any<font face="Times New Roman, Times, serif">&quot; returns value of last expression</font>
-    <font face="Times New Roman, Times, serif"># If no &quot;</font>:any<font face="Times New Roman, Times, serif">&quot; part, the function/method is void</font>
 }
+<font face="Times New Roman, Times, serif"># &quot;:any&quot; returns value of last expression
+# If no &quot;:any&quot; part, the function/method is void</font>
 def twoPlusThree := addTwoPrint(3)</pre>
           </td>
-          <td>
+          <td> 
             <pre>def adder {
     to add1(number) :any {number + 1}
     to add2(number) :any {number + 2}
@@ -142,13 +154,13 @@
 def result := adder add1(3)</pre>
           </td>
         </tr>
-        <tr>
+        <tr> 
           <td><b>Objects with state</b></td>
           <td><b>Objects self-referencing</b> during construction</td>
         </tr>
-        <tr>
-          <td>
-            <pre>def operatorMaker new(baseNum) :any {
+        <tr> 
+          <td> 
+            <pre>class operatorMaker(baseNum) :any {
     def randomVariable := 3
     def operator {
         to addBase(number) :any {
@@ -162,29 +174,28 @@
 def threeHandler := operatorMaker new(3)
 def threeTimes2 := threeHandler multiplyBase(2)</pre>
           </td>
-          <td>
-            <pre>def opMaker new :any {
-    def op := {
-        def myAlerter := alerterMaker new(op)
-        def op {
-            to respondToAlert() {
-                myAlerter(&quot;got alert&quot;)
-            }
+          <td> 
+            <pre>class opMaker() :any {
+    def op
+    def myAlerter := alerterMaker new(op)
+    bind op {
+        to respondToAlert() {
+            myAlerter(&quot;got alert&quot;)
         }
     }
 }</pre>
           </td>
         </tr>
-        <tr>
+        <tr> 
           <td><b>Delegation</b></td>
-          <td><b>Matching an Interface</b></td>
+          <td><b>Matching an Interface like a Java Adapter</b></td>
         </tr>
-        <tr>
-          <td>
-            <pre>def extendedFileMaker new(myFile) :any {
+        <tr> 
+          <td> 
+            <pre>class extendedFileMaker(myFile) :any {
     def extendedFile {
         to append(text) {
-            def current := myFile getText
+            def current := myFile getText()
             current := current + text
             myFile setText(current)
         }
@@ -192,182 +203,226 @@
     }
 }</pre>
           </td>
-          <td>
-            <pre>def upListenerMaker new(eventRecipient) :any {
+          <td> 
+            <pre>class upListenerMaker(reactor) :any {
     def upListener {
         to mouseUp(event) {
-            eventRecipient mouseUp()
+            reactor mouseUp()
         }
         match [verb, args] {}
     }
 }
-<font face="Times New Roman, Times, serif"># upListener meets the Java
-# MouseListener interface</font></pre>
-          </td>
+<font face="Times New Roman, Times, serif"># upListener meets the Java MouseListener interface</font></pre>
+            </td>
         </tr>
-        </tbody>
+        </tbody> 
       </table>
       <hr>
-      <p><a name=io><!-- --></a>
+      <p><a name=io>
+        <!-- -->
+        </a> 
       <table border="1">
-        <tbody>
-        <tr>
+        <tbody> 
+        <tr> 
           <td><b>Text File I/O</b></td>
           <td><b><a name="Windowing">Windowed</a> Applications</b> </td>
         </tr>
-        <tr>
-          <td>
-            <p>Text files are always normalized to use linefeed (<code>'\n'</code>)
-              as end of line when read in to the program; the end of line is converted
-              to native format upon being written out.</p>
-            <pre>    def fileA := &lt;file:/home/marcs/text.txt&gt;
-    def fileB := &lt;file: &quot;/home/marcs/text.txt&quot;&gt;
-    <font face="Times New Roman, Times, serif"># Note the blank space between the colon and the quote above
+        <tr> 
+          <td> 
+            <p>Text files are always normalized to use linefeed (<code>'\n'</code>) 
+              as end of line when read in to the program; the end of line is converted 
+              to native format upon being written out. File paths can always use 
+              &quot;/&quot; to separate subdirectories</p>
+            Tilda (~) is a reference to home directory, with meaning in MSWindows 
+            and Linux. 
+            <pre>    def fileA := &lt;file:~/Desktop/text.txt&gt;
+    def fileB := &lt;file: &quot;/home/marcs/text.txt&quot;&gt;   
+
+<font face="Times New Roman, Times, serif"># Note the blank space between the colon and the quote above</font>
 
-</font>    def fileC := c:/windows/desktop/text.txt
+    def fileC := &lt;c:/windows/desktop/text.txt&gt;
     fileA setText(&quot;abc&quot;)
     def contents := fileA getText()
-    for line in fileA {
-        print(line)
+    for line in contents split(&quot;\n&quot;) {
+        println(line)
     } </pre>
           </td>
-          <td>
-            <pre>
+          <td> 
+            <pre><font face="Times New Roman, Times, serif"># label A consumes horizontal space,
+# textArea consumes vertical space and
+# space beneath both labelA and labelB</font>
+
+def panel := 
+JPanel`$labelA.X   $labelB
+       $textArea.Y      &gt; `
+
 <font face="Times New Roman, Times, serif"># build app
 # display windows
-# in window listener on WindowClosing event:</font>
+# in window listener on 
+# WindowClosing event:</font>
+
 interp continueAtTop()
 
-<font face="Times New Roman, Times, serif"># at end of program,
-# after construction and window opening</font>
+<font face="Times New Roman, Times, serif"># at end of program, after
+# construction and window opening</font> 
+            
 interp blockAtTop()</pre>
           </td>
         </tr>
-        </tbody>
+        </tbody> 
       </table>
       <hr>
-      <p><a name=Structures><!-- --></a><b>Data Structures</b>
+      <p><a name=Structures>
+        <!-- -->
+        </a><b>Data Structures</b> 
       <table border=1 cellpadding=2>
-        <tbody>
-        <tr>
+        <tbody> 
+        <tr> 
           <td><b>ConstList</b></td>
           <td><b>ConstMap</b></td>
         </tr>
-        <tr>
-          <td>
-            <pre>def a := [8,6,"a"]
+        <tr> 
+          <td> 
+            <pre>var a := [8,6,"a"]
+
 <font face="Times New Roman, Times, serif"># a[2] == "a" is true
-# a size() == 3 is true
-</font>for i in a {println(i)}
+# a size() == 3 is true </font> 
+
+for i in a {println(i)}
 a := a + ["b"]
-<font face="Times New Roman, Times, serif"># a(0,2) == [8,6] is true</font>
+
+<font face="Times New Roman, Times, serif"># a(0,2) == [8,6] is true</font> 
+            
 def flexA := a diverge()</pre>
           </td>
-          <td>
+          <td> 
             <pre>def m := ["c" =&gt; 5]
+
 <font face="Times New Roman, Times, serif"># m["c"] == 5 is true
 # m size() == 1 is true
-</font>for key =&gt; value in m {
+</font>
+for key =&gt; value in m {
     println(value)
 }
-def flexM := a diverge()</pre>
+def flexM := m diverge()</pre>
           </td>
         </tr>
-        <tr>
+        <tr> 
           <td><b>FlexList</b></td>
           <td><b>FlexMap</b></td>
         </tr>
-        <tr>
-          <td>
+        <tr> 
+          <td> 
             <pre>flexA append(["b"])
 flexA push("b")
 constA := flexA snapshot()</pre>
           </td>
-          <td>
+          <td> 
             <pre>flexM["b"] := 2
 flexM removeKey("b")
 def constM := flexM snapshot()</pre>
           </td>
         </tr>
-        </tbody>
+        </tbody> 
       </table>
-      <p>Strings are ConstLists of <code>char</code> that have additional methods
+      <p>Strings are ConstLists of <code>char</code> that have additional methods 
         including Java string operators.<br>
-        Flex structures respond to all Const messages except the comparison operators
+        Flex structures respond to all Const messages except the comparison operators 
         ("&lt;", &lt;=", etc...).<br>
-        All these structures have many methods not listed here.
+        All these structures have many methods not listed here. 
       <hr>
-      <p><a name=Java><!-- --></a><b>Java Interface</b>
-      <pre>    def awt__uriGetter := &lt;import:java.awt.*&gt;
-    def swing__uriGetter := &lt;import:javax.swing.*&gt;
-    <font face="Times New Roman, Times, serif"># we can now directly name awt and swing classes using URI syntax</font>
+      <p><a name=Java>
+        <!-- -->
+        </a><b>Java Interface</b> 
+      <pre>    def awt__uriGetter := &lt;unsafe:java.awt.*&gt;
+    def swing__uriGetter := &lt;unsafe:javax.swing.*&gt;
+
+<font face="Times New Roman, Times, serif"># we can now directly name awt and swing classes using URI syntax</font>
+
     def frame1 := &lt;awt:Frame&gt; new()
     def frame2 := &lt;swing:JFrame&gt; new()
     def panel := &lt;swing:JPanel&gt; new()
-    E call(frame2, "add(Component)", [panel])
-    <font face="Times New Roman, Times, serif"># E call() needed when a method name in Java is overloaded with multiple</font>
-    <font face="Times New Roman, Times, serif"># methods with the same number of arguments, but different types
-</font>    def byte := &lt;import:java.lang.Byte&gt; TYPE
+    E call(frame2 getContentPane(), &quot;add(Component)&quot;, [panel])
+<font face="Times New Roman, Times, serif">
+# E call() needed when a method name in Java is overloaded with multiple
+# methods with the same number of arguments, different types, and the different
+# types are super/sub classes of one another</font>
+
+    def byte := &lt;import:java.lang.Byte&gt; asType()
     def byteArray := byte[300]
-    <font face="Times New Roman, Times, serif"># creates a Java array of primitive objects, byte, char, int, etc. </font></pre>
+<font face="Times New Roman, Times, serif">
+# creates a Java array of primitive objects,
+# byte, char, int, etc. </font>
+</pre>
+      <hr>
+      <b> eMakers</b><br>
+      <pre>def uiKit := &lt;import:com.skyhunter.ex.uiKit&gt;
+def buttonFunc() {println("pressed button")}
+def button := uiKit newToolButton(iconImage, &quot;tip&quot;, buttonFunc)
+def dialogVowMaker := &lt;import:com.skyhunter.ex.dialogVowMakerAuthor&gt;(&lt;unsafe:JFrame&gt;)
+def helpDialog := dialogVowMaker new(&quot;Help&quot;, 
+    &quot;&lt;html&gt;&lt;b&gt;Help&lt;/b&gt;&lt;p&gt;This is help.&lt;/html&gt;&quot;, 
+    null, 
+    [&quot;OK&quot;])</pre>
+      <b><a name=Asynch></a></b> 
       <hr>
-      <b><a name=Asynch></a> Asynch Sends</b>
+      <b>Eventual Sends</b> 
       <table border="1">
-        <tbody>
-        <tr>
-          <td>
+        <tbody> 
+        <tr> 
+          <td> 
             <pre>abacus &lt;- add(a,b)</pre>
           </td>
-          <td>
+          <td> 
             <pre>when (abacus &lt;- add(a,b)) -&gt; done(answer) {
     println(&quot;computation complete:&quot; + answer)
 } catch problem {
     println(&quot;promise broken &quot; + problem)
-}
-</pre>
+} finally {
+    println(&quot;always&quot;)
+}</pre>
           </td>
         </tr>
-        <tr>
-          <td>
-            <pre>def farCar := farCarMaker &lt;- new("Mercedes")
-Ref whenBroken(farCar, def lost(brokenRef) {
-    println("Lost connection to farCar")
+        <tr> 
+          <td> 
+            <pre>def carRcvr := carRcvrMaker &lt;- new(&quot;Mercedes&quot;)
+Ref whenBroken(carRcvr, def lost(brokenRef) {
+    println(&quot;Lost connection to carRcvr&quot;)
 })</pre>
           </td>
-          <td>
-            <pre>def [result, resolver] := PromiseMaker()
-Ref whenResolved(result, def obs(answer) {
-    if (! (Ref isBroken(answer))) {
-        println(answer)
-    } else {
-        def problem := Ref optProblem(answer)
-        println("oops: " + problem)
-    }
-})
+          <td> 
+            <pre>def [resultVow, resolver] := PromiseMaker()
+when (resultVow) -&gt; done(result) {
+    println(result)
+} catch prob {
+    println(&quot;oops: &quot; + prob)
+}
 resolver resolve(&quot;this text is the answer&quot;)</pre>
           </td>
         </tr>
-        </tbody>
+        </tbody> 
       </table>
       <hr>
-      <p><a name=Remote><!-- --></a><b>Remote Comm</b>
+      <p><a name=Remote>
+        <!-- -->
+        </a><b>Remote Comm</b> 
       <table border=1 cellpadding=2>
-        <tbody>
-        <tr>
+        <tbody> 
+        <tr> 
           <td><b>Initialization</b></td>
         </tr>
-        <tr>
-          <td>
+        <tr> 
+          <td> 
             <pre>introducer onTheAir()              </pre>
             <pre>def makeURI(obj) :any {
     introducer sturdyToURI(sturdyRef(obj))
 } </pre>
-            <pre>def promiseFromURI(uri) :any {
+            <pre>def makeFromURI(uri) :any {
     introducer sturdyFromURI(uri) liveRef()
 } </pre>
           </td>
         </tr>
-        </tbody>
+        </tbody> 
       </table>
       <!-- #EndEditable --></TD>
     <TD WIDTH="10%">&nbsp;</TD>