0.pre7.83:
[sbcl.git] / src / compiler / seqtran.lisp
index d218ceb..dfc86a2 100644 (file)
                 ;; of the &REST vars.)
                 `(lambda (result-type fun ,@seq-args)
                    (declare (ignore result-type))
-                   (do ((really-fun (%coerce-callable-to-function fun))
+                   (do ((really-fun (%coerce-callable-to-fun fun))
                         ,@index-bindingoids
                         (acc nil))
                    ((or ,@tests)
      (declare (optimize (safety 0)))
      (bit-bash-copy string2
                    (the index
-                        (+ (the index (* start2 sb!vm:byte-bits))
+                        (+ (the index (* start2 sb!vm:n-byte-bits))
                            ,vector-data-bit-offset))
                    string1
                    (the index
-                        (+ (the index (* start1 sb!vm:byte-bits))
+                        (+ (the index (* start1 sb!vm:n-byte-bits))
                            ,vector-data-bit-offset))
                    (the index
                         (* (min (the index (- (or end1 (length string1))
                                               start1))
                                 (the index (- (or end2 (length string2))
                                               start2)))
-                           sb!vm:byte-bits)))
+                           sb!vm:n-byte-bits)))
      string1))
 
 ;;; FIXME: It seems as though it should be possible to make a DEFUN
       (let ((n-seq (gensym))
            (n-length (gensym)))
        (args n-seq)
-       (lets `(,n-length (the index (* (length ,n-seq) sb!vm:byte-bits))))
+       (lets `(,n-length (the index (* (length ,n-seq) sb!vm:n-byte-bits))))
        (all-lengths n-length)
        (forms `(bit-bash-copy ,n-seq ,vector-data-bit-offset
                               res start
        (declare (ignore rtype))
        (let* (,@(lets)
              (res (make-string (truncate (the index (+ ,@(all-lengths)))
-                                         sb!vm:byte-bits)))
+                                         sb!vm:n-byte-bits)))
              (start ,vector-data-bit-offset))
         (declare (type index start ,@(all-lengths)))
         ,@(forms)
           (return (values find position)))
         (when (>= index start)
           (when (funcall predicate key-i)
-            ;; This hack of dealing with non-NIL FROM-END for list data
-            ;; by iterating forward through the list and keeping track of
-            ;; the last time we found a match might be more screwy than
-            ;; what the user expects, but it seems to be allowed by the
-            ;; ANSI standard. (And if the user is screwy enough to ask
-            ;; for FROM-END behavior on list data, turnabout is fair play.)
+            ;; This hack of dealing with non-NIL FROM-END for list
+            ;; data by iterating forward through the list and keeping
+            ;; track of the last time we found a match might be more
+            ;; screwy than what the user expects, but it seems to be
+            ;; allowed by the ANSI standard. (And if the user is
+            ;; screwy enough to ask for FROM-END behavior on list
+            ;; data, turnabout is fair play.)
             ;;
-            ;; It's also not enormously efficient, calling PREDICATE and
-            ;; KEY more often than necessary; but all the alternatives
-            ;; seem to have their own efficiency problems.
+            ;; It's also not enormously efficient, calling PREDICATE
+            ;; and KEY more often than necessary; but all the
+            ;; alternatives seem to have their own efficiency
+            ;; problems.
             (if from-end
                 (setf find i
                       position index)
                              :policy (> speed space)
                              :important t)
   "expand inline"
-  '(%find-position-if (let ((test-fun (%coerce-callable-to-function test)))
+  '(%find-position-if (let ((test-fun (%coerce-callable-to-fun test)))
+                       ;; I'm having difficulty believing I'm
+                       ;; reading it right, but as far as I can see,
+                       ;; the only guidance that ANSI gives for the
+                       ;; order of arguments to asymmetric tests is
+                       ;; the character-set dependent example from
+                       ;; the definition of FIND,
+                       ;;   (find #\d "here are some.." :test #'char>)
+                       ;;     => #\Space
+                       ;; (In ASCII, we have (CHAR> #\d #\SPACE)=>T.)
+                       ;; (Neither the POSITION definition page nor
+                       ;; section 17.2 ("Rules about Test Functions")
+                       ;; seem to consider the possibility of
+                       ;; asymmetry.)
+                       ;;
+                       ;; So, judging from the example, we want to
+                       ;; do (FUNCALL TEST-FUN ITEM I), because
+                       ;; (FUNCALL #'CHAR> #\d #\SPACE)=>T.
+                       ;;
+                       ;; -- WHN (whose attention was drawn to it by
+                       ;;         Alexey Dejneka's bug report/fix)
                        (lambda (i)
-                         (funcall test-fun i item)))
+                         (funcall test-fun item i)))
                      sequence
                      from-end
                      start
                      end
-                     (%coerce-callable-to-function key)))
+                     (%coerce-callable-to-fun key)))
 
 ;;; The inline expansions for the VECTOR case are saved as macros so
 ;;; that we can share them between the DEFTRANSFORMs and the default
      start
      end
      element
+     ;; (See the LIST transform for a discussion of the correct
+     ;; argument order, i.e. whether the searched-for ,ITEM goes before
+     ;; or after the checked sequence element.)
      `(funcall ,test ,item (funcall ,key ,element)))))
 
 (def!macro %find-position-if-vector-macro (predicate sequence