Lisp HUG Maillist Archive

compiler bug, maybe

Hello,

LWw (last version) can't evaluate or compile the following test 
function (seems to loop forever).  It works with ACL. Maybe a bug?

(defmacro push-string (in-string out-string)
   `(progn ,@(mapcan (lambda (char)
                       `((setf (char ,out-string j) ,char)
                         (incf j)))
                     (coerce in-string 'list))))


(defun test ()
   (let ((new-string "xyc")
         (j 0))
     (push-string "ab" new-string)
     new-string))

With ACL:

 > (test)
"abc"
 >


Note
Push-string is a part of KM I'm trying to compile (KM, The 
Knowledge Machine, http://www.cs.utexas.edu/users/mfkb/km/). The complete function:


(defun xmlify-internal (string length new-string)
   (macrolet ((push-string (in-string out-string)
	       `(progn ,@(mapcan #'(lambda (char)
				     `((setf (char ,out-string j) ,char)
				       (incf j)))
				 (coerce in-string 'list)))))
     (do ((i 0 (1+ i))
	 (j 0))
	((= i length) new-string)
       (let ((char (char string i)))
	(case char
	  (#\<
	   (push-string "&lt;"   new-string))
	  (#\>
	   (push-string "&gt;"   new-string))
	  (#\&
	   (push-string "&amp;"  new-string))
	  (#\'
	   (push-string "&apos;" new-string))
	  (#\"
	   (push-string "&quot;" new-string))
	  (t
	   (setf (char new-string j) char) (incf j)))))))

Francis


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________


Re: compiler bug, maybe

Francis Leboutte <f.leboutte@algo.be> writes:

> Hello,
> 
> LWw (last version) can't evaluate or compile the following test
> function (seems to loop forever).  It works with ACL. Maybe a bug?
> 
> (defmacro push-string (in-string out-string)
>    `(progn ,@(mapcan (lambda (char)
>                        `((setf (char ,out-string j) ,char)
>                          (incf j)))
>                      (coerce in-string 'list))))
> 
> 
> (defun test ()
>    (let ((new-string "xyc")
>          (j 0))
>      (push-string "ab" new-string)
>      new-string))

Yikes, this does the same thing on SBCL and LWL. 
It seems to be caused by the destructive modification of 
the backquoted form in the lambda body.

Replacing the current lambda form with 

(lambda (char)
  (list `(setf (char ,outstring j) ,char)
        `(incf j)))

seems to work fine.

Regards, 
   Sean.

-- 
"My doctor says that I have a malformed public-duty gland and a
 natural  deficiency in moral fibre," he muttered to himself, "and
 that I am therefore excused from saving Universes."
 - Life, the Universe, and Everything     Douglas Adams.


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________


Re: compiler bug, maybe

Thank you Sean, dans le mille!

 From the Backquote entry in the hyperspec:

An implementation is free to interpret... The constructed copy of 
the template might or might not share list structure with the template itself.

Francis

At 1/04/2005 11:39, Sean Ross wrote:
>Francis Leboutte <f.leboutte@algo.be> writes:
>
> > Hello,
> >
> > LWw (last version) can't evaluate or compile the following test
> > function (seems to loop forever).  It works with ACL. Maybe a bug?
> >
> > (defmacro push-string (in-string out-string)
> >    `(progn ,@(mapcan (lambda (char)
> >                        `((setf (char ,out-string j) ,char)
> >                          (incf j)))
> >                      (coerce in-string 'list))))
> >
> >
> > (defun test ()
> >    (let ((new-string "xyc")
> >          (j 0))
> >      (push-string "ab" new-string)
> >      new-string))
>
>Yikes, this does the same thing on SBCL and LWL.
>It seems to be caused by the destructive modification of
>the backquoted form in the lambda body.
>
>Replacing the current lambda form with
>
>(lambda (char)
>   (list `(setf (char ,outstring j) ,char)
>         `(incf j)))
>
>seems to work fine.
>
>Regards,
>    Sean.
>
>--
>"My doctor says that I have a malformed public-duty gland and a
>  natural  deficiency in moral fibre," he muttered to himself, "and
>  that I am therefore excused from saving Universes."
>  - Life, the Universe, and Everything     Douglas Adams.
>
>
>______________________________________________________________________
>This email has been scanned by the MessageLabs Email Security System.
>For more information please visit http://www.messagelabs.com/email
>______________________________________________________________________


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________


Updated at: 2020-12-10 08:53 UTC