From 5b4edf81a337af32572ea2ec629dfbea76e2bd46 Mon Sep 17 00:00:00 2001 From: David Vazquez Date: Thu, 27 Dec 2012 02:36:11 +0000 Subject: [PATCH] subseq for strings --- lispstrack.lisp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lispstrack.lisp b/lispstrack.lisp index 6150d86..5b71994 100644 --- a/lispstrack.lisp +++ b/lispstrack.lisp @@ -323,6 +323,15 @@ (- x #\0) nil)) + (defun subseq (seq a &optional b) + (cond + ((stringp seq) + (if b + (slice seq a b) + (slice seq a))) + (t + (error "Unsupported argument.")))) + (defun parse-integer (string) (let ((value 0) (index 0) @@ -982,6 +991,17 @@ (define-compilation string-length (x) (concat "(" (ls-compile x env fenv) ").length")) +(define-compilation slice (string a &optional b) + (concat "(function(){" *newline* + "var str = " (ls-compile string env fenv) ";" *newline* + "var a = " (ls-compile a env fenv) ";" *newline* + "var b;" *newline* + (if b + (concat "b = " (ls-compile b env fenv) ";" *newline*) + "") + "return str.slice(a,b);" *newline* + "})()")) + (define-compilation char (string index) (concat "(" (ls-compile string env fenv) -- 1.7.10.4