Added description of namespace system to the reference.
authorVladimir Sedach <vsedach@gmail.com>
Fri, 24 Aug 2007 20:43:13 +0000 (20:43 +0000)
committerVladimir Sedach <vsedach@gmail.com>
Fri, 24 Aug 2007 20:43:13 +0000 (20:43 +0000)
docs/reference.lisp
t/reference-tests.lisp

index 7237bbe..c53e1df 100644 (file)
@@ -1042,6 +1042,35 @@ a-variable  => aVariable
                              slots)
     ,@body))
 
+
+;;;# The ParenScript namespace system
+;;;t \index{package}
+;;;t \index{namespace}
+;;;t \index{PS-PACKAGE-PREFIX}
+
+;;; (setf (PS-PACKAGE-PREFIX lisp-package) string)
+
+;;; Although JavaScript does not offer namespacing or a package
+;;; system, ParenScript does provide a namespace mechanism for
+;;; generated JavaScript by integrating with the Common Lisp package
+;;; system. Since ParenScript code is normally read in by the Lisp
+;;; reader, all symbols (except for uninterned ones, ie - those
+;;; specified with the #: reader macro) have a Lisp package. By
+;;; default, no packages are prefixed. You can specify that symbols in
+;;; a particular package receive a prefix when translated to
+;;; JavaScript with the `PS-PACKAGE-PREFIX' place.
+
+(lisp (defpackage "MY-LIBRARY"
+        (:use #:parenscript))
+      (setf (ps-package-prefix :my-library) "my_library_"))
+  => 'my_library_'
+
+(defun my-library::library-function (x y)
+  (return (+ x y)))
+  => function my_library_libraryFunction(x, y) {
+        return x + y;
+     }
+
 ;;;# The ParenScript Compiler
 ;;;t \index{compiler}
 ;;;t \index{ParenScript compiler}
index 901de02..a3c13c3 100644 (file)
@@ -513,3 +513,16 @@ _js2.style.left = _js1;")
     + ' looks like this.</div>';
 }")
 
+(test-ps-js the-parenscript-namespace-system-1
+  (lisp (defpackage "MY-LIBRARY"
+        (:use #:parenscript))
+      (setf (ps-package-prefix :my-library) "my_library_"))
+  "'my_library_'")
+
+(test-ps-js the-parenscript-namespace-system-2
+  (defun my-library::library-function (x y)
+  (return (+ x y)))
+  "function my_library_libraryFunction(x, y) {
+   return x + y;
+}")
+