[Ecls-list] compiler error: unable to coerce lisp object

Juan Jose Garcia-Ripoll worm at arrakis.es
Thu Dec 18 06:39:46 UTC 2003


On Monday 15 December 2003 19:25, Eric Marsden wrote:
> Hi,
>
> Using ECL compiled from CVS on Linux/x86, the code below triggers a
> compiler error.
>
> ,----
>
> | > (compile-file "hash")
> | ;;; Compiling (DEFUN FIXNUM-TO-STRING).
> | ;;; Error: Unable to coerce lisp object from type (NULL,:OBJECT)
> | to C/C++ type (FIXNUM,:FIXNUM)
> | ;;; Due to errors in the compilation process, no FASL was generated.
>
> `----
>
> (defun fixnum-to-string (n base)
>   (declare (fixnum n base))
>   (let* ((tsize (position-if (lambda (x) (> (the fixnum x) n))
>                             (aref +digits-needed+ (ash base -4))))
>          (result (make-string (1+ tsize))))
>     (loop for i fixnum from tsize downto 0 with q fixnum = n and r fixnum=0
>       do (multiple-value-setq (q r) (floor q base))
>          (setf (schar result i) (aref +digit+ r)))
>     result))

The problem is that you have declared variable "R" to be of type FIXNUM. 
However, ECL does not know how many values FLOOR will output, and since there 
is a code branch in which R and Q may get assigned a value of NIL, the 
compiler signals a (I must admit obscure) error.

This version does not signal an error:

(defun fixnum-to-string (n base)
  (declare (fixnum n base))
  (let* ((tsize (position-if (lambda (x) (> (the fixnum x) n))
                            (aref +digits-needed+ (ash base -4))))
         (result (make-string (1+ tsize))))
    (loop for i fixnum from tsize downto 0 with q = n and r = 0
      do (multiple-value-setq (q r) (floor q base))
         (setf (schar result i) (aref +digit+ r)))
    result))

Regards,

Juanjo





More information about the ecl-devel mailing list