Hi,

I wrote a tiny patch to add support for array slicing:

>From 1be1435f8131934b7aae212c5d1ebb37ffe28f4a Mon Sep 17 00:00:00 2001
From: Nicolas Martyanoff <khae...@gmail.com>
Date: Mon, 25 Apr 2011 00:15:16 +0200
Subject: [PATCH] modify :[] to allow array slicing

---
 doc/s-sql.html   |    9 +++++----
 s-sql/s-sql.lisp |    6 ++++--
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/doc/s-sql.html b/doc/s-sql.html
index 6ff1935..0fc185a 100644
--- a/doc/s-sql.html
+++ b/doc/s-sql.html
@@ -310,7 +310,7 @@
     <p class="desc">Test whether a value is null.</p>
 
     <p class="def"><span>sql-op</span> <a name="in"></a>:in (value set)</p>
-   
+
     <p class="desc">Test whether a value is in a set of values.</p>
 
     <p class="def"><span>sql-op</span> <a name="not-in"></a>:not-in (value set)</p>
@@ -324,9 +324,10 @@
     be given as multiple arguments to the operator. When they are not,
     a single argument that evaulates to a list should be used.</p>
 
-    <p class="def"><span>sql-op</span> <a name="deref"></a>:[] (form subscript)</p>
-   
-    <p class="desc">Dereference an array value.</p>
+    <p class="def"><span>sql-op</span> <a name="deref"></a>:[] (form start &amp;optional end)</p>
+
+    <p class="desc">Dereference an array value. If <code>end</code> is
+    provided, extract a slice of the array.</p>
 
     <p class="def"><span>sql-op</span> <a name="extract"></a>:extract (unit form)</p>
 
diff --git a/s-sql/s-sql.lisp b/s-sql/s-sql.lisp
index d299f88..66b1328 100644
--- a/s-sql/s-sql.lisp
+++ b/s-sql/s-sql.lisp
@@ -498,8 +498,10 @@ with a given arity."
             :append `(" WHEN " ,@(sql-expand test) " THEN " ,@(sql-expand expr)))
     " END"))
 
-(def-sql-op :[] (form subscript)
-  `("(" ,@(sql-expand form) ")[" ,@(sql-expand subscript) "]"))
+(def-sql-op :[] (form start &optional end)
+  (if end
+      `("(" ,@(sql-expand form) ")[" ,@(sql-expand start) ":" ,@(sql-expand end) "]")
+      `("(" ,@(sql-expand form) ")[" ,@(sql-expand start) "]")))
 
 ;; This one has two interfaces. When the elements are known at
 ;; compile-time, they can be given as multiple arguments to the
-- 
1.7.4.4

So now:

   (:[] #(1 2 4 8) 3) → "(ARRAY[1,2,4,8])[3]"
   (:[] #(1 2 4 8) 2 4) → "(ARRAY[1,2,4,8])[2:4]"

I hope you will find it useful.

Best regards,

-- 
Nicolas Martyanoff
   http://codemore.org
   khae...@gmail.com
_______________________________________________
postmodern-devel mailing list
postmodern-devel@common-lisp.net
http://common-lisp.net/cgi-bin/mailman/listinfo/postmodern-devel

Reply via email to