Re: string-match and string-looking-at



Timo Korvola <Timo Korvola iki fi> writes:

> That is because string= is defined only as an alias for equal.
>  
...
>
> I think it would be better for all three functions to report type errors 
> as errors.

This does seem better, especially since (string= 1 1) ==> t, which
doesn't seem like it should be the case.

Maybe a new defenition in lispcmds.c for 'string= that is the same as
'equal except it does a type-check for strings?

see patch.

diff --git a/lisp/rep/data.jl b/lisp/rep/data.jl
index 8fc624a..ea001f0 100644
--- a/lisp/rep/data.jl
+++ b/lisp/rep/data.jl
@@ -38,7 +38,6 @@ string INPUT."
 (defun setcdr (cell x) (rplacd cell x) x)
 
 ;; Some function pseudonyms
-(%define string= equal)
 (%define string< <)
 
 (defun member-if (fun lst)
@@ -71,8 +70,8 @@ returns false."
   "Returns a new copy of LST with all elements `eq' to ELT discarded."
   (remove-if (lambda (x) (eq x elt)) lst))
 
-(export-bindings '(assoc-regexp setcar setcdr string= string<
-		   member-if remove-if remove-if-not remove remq))
+(export-bindings '(assoc-regexp setcar setcdr string< member-if
+		   remove-if remove-if-not remove remq))
 
 
 ;; cons accessors
diff --git a/src/lispcmds.c b/src/lispcmds.c
index ca362c5..b56ca84 100644
--- a/src/lispcmds.c
+++ b/src/lispcmds.c
@@ -1618,6 +1618,21 @@ Returns t if STRING1 and STRING2 are the same, ignoring case.
     return (*s1 || *s2) ? Qnil : Qt;
 }
 
+DEFUN("string=", Fstring_eq, Sstring_eq, (repv str1, repv str2), rep_Subr2) /*
+::doc:rep.data#string=::
+string= STRING1 STRING2
+
+Compares STRING1 and STRING2, compares the actual structure of the objects not
+just whether the objects are one and the same. ie, will return t for two
+strings built from the same characters in the same order even if the strings'
+location in memory is different.
+::end:: */
+{
+    rep_DECLARE1(str1, rep_STRINGP);
+    rep_DECLARE2(str2, rep_STRINGP);
+    return (rep_value_cmp(str1, str2) == 0) ? Qt : Qnil;
+}
+
 DEFUN("string-lessp", Fstring_lessp, Sstring_lessp, (repv str1, repv str2), rep_Subr2) /*
 ::doc:rep.data#string-lessp::
 string-lessp STRING1 STRING2
@@ -2085,6 +2100,7 @@ rep_lispcmds_init(void)
     rep_ADD_SUBR(Seq);
     rep_ADD_SUBR(Sstring_head_eq);
     rep_ADD_SUBR(Sstring_equal);
+    rep_ADD_SUBR(Sstring_eq);
     rep_ADD_SUBR(Sstring_lessp);
     rep_ADD_SUBR(Snum_eq);
     rep_ADD_SUBR(Snum_noteq);
-- 
mrl


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]