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

Buffer bug?



Dear Folks:

I found the following unexpected behavior in mcl2.0. I'd like to hear why
Test1 and Test2 below don't have the same behavior. The call to
buffer-current-sexp in the function L-LISTS-IN-BUFFER seems to be working
differently even though I pass exactly the same option position in the two
tests.

Can you think of a better (faster) way to implement L-LISTS-IN-BUFFER ?


matt


(defun L-LISTS-IN-BUFFER (buffer)
  "Returns a list of the non-nil lists in buffer."
  ;;
  (let ((l-lists-in-buffer ())
        (int-buffer-size (buffer-size buffer))
        sexp)
    (format t "~&Buffer ~S has ~S chars, which are: ~%'~A'."
            buffer int-buffer-size (buffer-substring buffer 0 int-buffer-size))
    (dotimes (int int-buffer-size)
      (ignore-errors
       (setf sexp (buffer-current-sexp buffer int)))
      (when (and sexp (listp sexp))
        (pushnew sexp l-lists-in-buffer :test #'equal)))
    ;;
    l-lists-in-buffer))


;;; Test1: Make a FRED window named "New", place following three lines of text
;;; in it (don't include #| and |#), and eval:
;;;
;;;          (l-lists-in-buffer (fred-buffer (find-window "New")))
;;;
;;; The text is:
#|
This )) is (people person 1) bad too.
;This (( is a ) bad ( string, no?
;This is a nice string (people person 1), yes?
|#
;;;
;;; The result I got was:
;;;
#|
    ? 
    Buffer #<BUFFER-MARK 0/119> has 119 chars, which are: 
    'This )) is (people person 1) bad too.
    ;This (( is a ) bad ( string, no?
    ;This is a nice string (people person 1), yes?
    '.
    ((IS A) (PEOPLE PERSON 1))          ;correct result
    ? 
|#


;;;
;;; Test2: Evaluate following form:
;;;
#|
(let ((buffer (make-buffer)))
  (buffer-insert buffer "This )) is (people person 1) bad too.
;This (( is a ) bad ( string, no?
;This is a nice string (people person 1), yes?
")
  (l-lists-in-buffer buffer))
|#
;;;
;;; The result this time was different and *wrong* IMHO:
;;;
#|
? 
    Buffer #<BUFFER-MARK 119/119> has 119 chars, which are: 
    'This )) is (people person 1) bad too.
    ;This (( is a ) bad ( string, no?
    ;This is a nice string (people person 1), yes?
    '.
    NIL                                 ;*wrong* result!
    ? 
|#