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

format ~t - the bug remains

     Sometimes I get a feeling that I am the only subscriber to this list 
     (definitely the most garrulous!)... Oh well. :-)
     The same bug that was (allegedly) fixed recently: clisp thinks that 
     the first output after the command starts with column 2, not 0. The 
     following is the test case:
     > (sorted-map 'list #'(lambda (a b c) (format t " --> a: ~a;~20tb: 
     ~a;~40tc: ~a~%" a b c) (list a b c)) #'string< nil #'car #'(lambda (z) 
     (aref (car z) 0)) '(("abc") ("def") ("ijk")) '(("abc") ("ghi") 
     ("ijk")) '(("abc") ("ghi") ("ijk") ("lmn")))
      --> a: a;        b: a;               c: a
      --> a: d;          b: nil;             c: nil
      --> a: nil;        b: g;               c: g
      --> a: i;          b: i;               c: i
      --> a: nil;        b: nil;             c: l
     ((#\a #\a #\a) (#\d nil nil) (nil #\g #\g) (#\i #\i #\i) (nil nil 
     As you see, the first line of output is not properly aligned.
     I would appreciate if the lisp gurus could comment on the following 
     code (optimization is my primary concern here. I don't like that I 
     have to create 2 new temporary lists!) 
     BTW, is there a way to get a function's signature? (the list of 
     (defun sorted-map (type func pred missing ckey akey &rest lists)
       "Operate on the corresponding elements of the sorted lists.  Each 
     in LISTS is assumed to be sorted according to the predicate PRED 
     to keys CKEY.  Apply function FUNC to the AKEYs of the elements of the
     lists with the same CKEYs.  When a list doesn't have an element with 
     particular CKEY, function gets nil (if MISSING is nil) or the previous
     AKEY (if MISSING is non-nil).
     CKEY and AKEY values of nil are the same as #'identity.
       (sorted-map type func pred missing ckey akey &rest lists)"
       (declare (function func pred) (symbol type))
       (unless ckey (setq ckey #'identity))
       (unless akey (setq akey #'identity))
       (do ((sec (copy-list lists)) (akeys (make-list (length lists)))
            begck ck fnn (err nil nil) res)
           ((every #'null sec) (nreverse res))
         ;; get the current ckey
         (setq fnn (member nil sec :test-not #'eq)
          begck (funcall ckey (caar fnn)))
         (dolist (ls (rest fnn))
           (when ls (setq ck (funcall ckey (car ls)))
            (when (funcall pred ck begck) (setq begck ck))))
         ;; shift and operate
         (mapl #'(lambda (ls ak) 
              (cond ((and (car ls)
                          (not (funcall pred begck (funcall ckey (caar 
                     (setf (car ak) (funcall akey (caar ls)))
                     (pop (car ls)))
                    (t (if missing nil (setf (car ak) nil)))))
          sec akeys)
         (cond ((eq type 'list) (push (apply func akeys) res))
          (t (apply func akeys)))))