Updated the ParenScript tutorial.
[clinton/parenscript.git] / docs / reference.lisp
index 4c71e17..7c112f8 100644 (file)
@@ -222,7 +222,7 @@ an-object.foo => anObject.foo
 
 (with-slots (a b c) this
   (+ a b c))
-    => (this).a + (this).b + (this).c;
+    => this.a + this.b + this.c;
 
 ;;;## Regular Expression literals
 ;;;t \index{REGEX}
@@ -383,16 +383,11 @@ a-variable  => aVariable
 (* 1 (+ 2 3 4) 4 (/ 6 7))
   => 1 * (2 + 3 + 4) * 4 * (6 / 7)
 
-;;; The pre/post increment and decrement operators are also
+;;; The pre increment and decrement operators are also
 ;;; available. `INCF' and `DECF' are the pre-incrementing and
-;;; pre-decrementing operators, and `++' and `--' are the
-;;; post-decrementing version of the operators. These operators can
+;;; pre-decrementing operators. These operators can
 ;;; take only one argument.
 
-(++ i)   => i++
-
-(-- i)   => i--
-
 (incf i) => ++i
 
 (decf i) => --i
@@ -491,7 +486,7 @@ a-variable  => aVariable
 ;;; Assignment is done using the `SETF' form, which is transformed
 ;;; into a series of assignments using the JavaScript `=' operator.
 
-(setf a 1) => a = 1
+(setf a 1) => a = 1;
 
 (setf a 2 b 3 c 4 x (+ a b c))
    => a = 2;
@@ -503,11 +498,11 @@ a-variable  => aVariable
 ;;; operator expression using this variable into a more "efficient"
 ;;; assignment operator form. For example:
 
-(setf a (1+ a))          => a++
+(setf a (1+ a))          => a++;
 
-(setf a (+ a 2 3 4 a))   => a += 2 + 3 + 4 + a
+(setf a (+ a 2 3 4 a))   => a += 2 + 3 + 4 + a;
 
-(setf a (- 1 a))         => a = 1 - a
+(setf a (- 1 a))         => a = 1 - a;
 
 ;;;# Single argument statements
 ;;;t \index{single-argument statement}
@@ -638,7 +633,7 @@ a-variable  => aVariable
 ;;; Lisp. The `DEFVAR' is converted to "var ... = ..." form in
 ;;; JavaScript.
 
-(defvar *a* (array 1 2 3)) => var A = [ 1, 2, 3 ];
+(defvar *a* (array 1 2 3)) => var A = [ 1, 2, 3 ]
 
 (if (= i 1)
     (progn (defvar blorg "hallo")
@@ -728,19 +723,16 @@ a-variable  => aVariable
 
 ;;; The `DOLIST' form is a shortcut for iterating over an array. Note
 ;;; that this form creates temporary variables using a function called
-;;; `JS-GENSYM', which is similar to its Lisp counterpart `GENSYM'.
+;;; `PS-GENSYM', which is similar to its Lisp counterpart `GENSYM'.
 
 (dolist (l blorg)
   (document.write (+ "L is " l)))
-   => {
-        var tmpArr1 = blorg;
+   =>   var tmpArr1 = blorg;
         for (var tmpI2 = 0; tmpI2 < tmpArr1.length;
           tmpI2 = tmpI2 + 1) {
           var l = tmpArr1[tmpI2];
           document.write('L is ' + l);
         };
-      }
-
 
 ;;; The `DOEACH' form is converted to a `for (var .. in ..)' form in
 ;;; JavaScript. It is used to iterate over the enumerable properties
@@ -783,7 +775,7 @@ a-variable  => aVariable
   (2 (alert "two"))
   (t (alert "default clause")))
     => switch (blorg[i]) {
-         case 1:   ;
+         case 1:   
          case 'one':
                    alert('one');
                    break;
@@ -874,25 +866,24 @@ a-variable  => aVariable
 
 ; (HTML html-expression)
 
-;;; The HTML generator of ParenScript is very similar to the HTML
-;;; generator included in AllegroServe. It accepts the same input
-;;; forms as the AllegroServer HTML generator. However, non-HTML
-;;; construct are compiled to JavaScript by the ParenScript
+;;; The HTML generator of ParenScript is very similar to the htmlgen
+;;; HTML generator library included with AllegroServe. It accepts the
+;;; same input forms as the AllegroServer HTML generator. However,
+;;; non-HTML construct are compiled to JavaScript by the ParenScript
 ;;; compiler. The resulting expression is a JavaScript expression.
 
-(html ((:a :href "foobar") "blorg"))
+(ps-html ((:a :href "foobar") "blorg"))
   => '<a href=\"foobar\">blorg</a>'
 
-(html ((:a :href (generate-a-link)) "blorg"))
+(ps-html ((:a :href (generate-a-link)) "blorg"))
   => '<a href=\"' + generateALink() + '\">blorg</a>'
 
 ;;; We can recursively call the JS compiler in a HTML expression.
 
 (document.write
-  (html ((:a :href "#"
-            :onclick (js-inline (transport))) "link")))
-  => document.write
-     ('<a href=\"#\" onclick=\"' + 'javascript:transport();' + '\">link</a>')
+  (ps-html ((:a :href "#"
+                :onclick (lisp (ps-inline (transport)))) "link")))
+  => document.write('<a href=\"#\" onclick=\"' + 'javascript:transport();' + '\">link</a>')
 
 ;;; Forms may be used in attribute lists to conditionally generate
 ;;; the next attribute. In this example the textarea is sometimes disabled.
@@ -900,16 +891,14 @@ a-variable  => aVariable
 (let ((disabled nil)
       (authorized t))
    (setf element.inner-h-t-m-l
-         (html ((:textarea (or disabled (not authorized)) :disabled "disabled")
+         (ps-html ((:textarea (or disabled (not authorized)) :disabled "disabled")
                 "Edit me"))))
-  =>  {
-        var disabled = null;
+  =>    var disabled = null;
         var authorized = true;
         element.innerHTML =
         '<textarea'
         + (disabled || !authorized ? ' disabled=\"' + 'disabled' + '\"' : '')
         + '>Edit me</textarea>';
-      }
 
 ; (CSS-INLINE css-expression)
 
@@ -920,7 +909,7 @@ a-variable  => aVariable
   => 'color:red;font-size:x-small'
 
 (defun make-color-div(color-name)
-    (return (html ((:div :style (css-inline :color color-name))
+    (return (ps-html ((:div :style (css-inline :color color-name))
                    color-name " looks like this."))))
   => function makeColorDiv(colorName) {
        return '<div style=\"' + ('color:' + colorName) + '\">' + colorName
@@ -965,13 +954,13 @@ a-variable  => aVariable
 ;;; of the `DOLIST' form (note how `JS-GENSYM', the ParenScript of
 ;;; `GENSYM', is used to generate new ParenScript variable names):
 
-(defjsmacro dolist (i-array &rest body)
+(defpsmacro dolist (i-array &rest body)
   (let ((var (first i-array))
         (array (second i-array))
         (arrvar (js-gensym "arr"))
         (idx (js-gensym "i")))
     `(let ((,arrvar ,array))
-      (do ((,idx 0 (++ ,idx)))
+      (do ((,idx 0 (incf ,idx)))
           ((>= ,idx (slot-value ,arrvar 'length)))
         (let ((,var (aref ,arrvar ,idx)))
           ,@body)))))