Skip to content
This repository
Browse code

Added a macro for slice.

Array.prototype.slice is used often in Sibilant (and JavaScript) so it
makes sense that it has its own macro rather than rewriting the same code
many times.
  • Loading branch information...
commit 2b0ce2b33a919fe6e2acff1368afcc670311bf7b 1 parent e816429
Matthew Phillips authored October 20, 2012
7  include/macros.sibilant
@@ -361,4 +361,9 @@
361 361
         (concat ") {" (indent (translate body)) "}"))))
362 362
 
363 363
 (defmacro instance-of? (item type)
364  
-  (concat "(" (translate item) " instanceof " (translate type) ")"))
  364
+  (concat "(" (translate item) " instanceof " (translate type) ")"))
  365
+
  366
+(defmacro slice (list &optional begin &optional end)
  367
+  (concat "Array.prototype.slice.call(" (translate list)
  368
+          ", " (or (translate begin) 0) (if (defined? end) (concat ", "
  369
+          (translate end) ")") ")")))
3  test/slice.sibilant
... ...
@@ -0,0 +1,3 @@
  1
+(defvar sliced (slice '(1 2 3 4)))
  2
+
  3
+(defvar other (slice '(1 2 3 4) 0 2))

0 notes on commit 2b0ce2b

Please sign in to comment.
Something went wrong with that request. Please try again.