Implemented string<
authorSamuel Chase <samebchase@gmail.com>
Sun, 12 May 2013 20:38:43 +0000 (02:08 +0530)
committerSamuel Chase <samebchase@gmail.com>
Sun, 12 May 2013 20:57:52 +0000 (02:27 +0530)
boot.lisp: implemented char<
string.lisp: implemented string<
strings.lisp: added tests. The added tests pass.

src/boot.lisp
src/string.lisp
tests/strings.lisp

index 47f4309..5f44fa6 100644 (file)
 (defun char= (x y)
   (eql x y))
 
+(defun char< (x y)
+  (< (char-code x) (char-code y)))
+
 (defun integerp (x)
   (and (numberp x) (= (floor x) x)))
 
index 92c78dc..aebad3a 100644 (file)
           (return-from string= nil))))))
 
 (defun string< (s1 s2)
-  -1)
-
+  (let ((len-1 (length s1))
+               (len-2 (length s2)))
+       (cond ((= len-2 0) nil)
+                 ((= len-1 0) 0)
+                 (t (dotimes (i len-1 nil)
+                          (when (char< (char s1 i) (char s2 i))
+                                (return-from string< i)))))))
+               
 (define-setf-expander char (string index)
   (let ((g!string (gensym))
         (g!index (gensym))
index eab8a6b..cb6cd83 100644 (file)
 (test (not (string= "foo" "foox")))
 
 (test (= (string< "one" "two") 0))
+(test (= (string< "oob" "ooc") 2))
+(test (null (string< "" "")))
+(test (null (string< "a" "")))
+(test (= (string< "" "a") 0))
 
 ;;; BUG: The compiler will macroexpand the forms below (char str N)
 ;;; will expand to internal SBCL code instead of our (setf char). It