From: Rob St. Amant
Subject: Diagnosing a function
Date: 
Message-ID: <lpnya5hum8z.fsf@wayback.csc.ncsu.edu>
Hi,

I'm having a bit of trouble figuring out what's going wrong with some
code in Allegro 5.0 for Windows.  The relevant part of the function
below is marked with a comment.  I was hoping that some of the gurus
here might help me out.

(defun find-string (string &key (refresh nil)
                                (minimum-length 2)
                                (strings nil)
                                (bounds nil))
  (declare (optimize (safety 3) (speed 0)))
  (setf string (string-upcase string))
  (let ((strings (or strings
                     (get-strings :refresh refresh
                                  :bounds bounds
                                  :minimum-length minimum-length))))
    (when strings
      (multiple-value-bind (found min)
          ;; ****** Problem area start *****

          (arg-mins #'(lambda (s)
                        (string-distance string (text-string s)))
                    strings)

          ;; ****** Problem area end *****
        (values (first found) found min)))))

Running this code *sometimes* gives me a segmentation error.  A trace
of find-string and arg-mins shows this:

 0: (FIND-STRING "Microsoft")
   1: (ARG-MINS #<Interpreted Function ("malformed" "closure") @
                  #x206586da>
                (#<TEXT "AIIEGRO"> #<TEXT "COMMON"> #<TEXT "ICROSOFT">
. . .

I can't see how the lambda in find-string is a malformed closure.
There's nothing special about the function string-distance. . .  If it
helps, the definition of arg-mins is given below.  I'd be grateful for
any advice about where to look for problems.  Am I missing something
obvious?

(defun arg-mins (function sequence)
  (let* ((saved (list (elt sequence 0)))
         (current (funcall function (first saved))))
    (reduce #'(lambda (x y)
                (let ((new (funcall function y)))
                  (cond ((< new current)
                         (setf current new)
                         (setf saved (list y))
                         y)
                        ((= new current)
                         (push y saved)
                         y)
                        (t x))))
            sequence)
    (values saved current)))

-- 
Rob St. Amant
From: Thomas A. Russ
Subject: Re: Diagnosing a function
Date: 
Message-ID: <ymi66sjmirs.fsf@sevak.isi.edu>
The malformed closure has me baffled as well, but I did have an idea.

Do you ever get an empty sequence passed in to ARG-MINS?  When compiled
with high speed and low safety, you will sometimes get such errors when
bad arguments are passed to (particularly low-level) system functions:

(defun arg-mins (function sequence)
  (let* ((saved (list (elt sequence 0)))
                      ^^^^^^^^^^^^^^^^
                      What if there isn't one?

You might also want to try

 (declaim (optimize (speed 0) (safety 3) (debug 3)))

and seeing if you get a similar error.



-- 
Thomas A. Russ,  USC/Information Sciences Institute          ยทยทยท@isi.edu