Subject: [clisp-list] `compile-file' problem with CMU `trees' package

From: Nathan Froyd <[email-masked]>
Date: Fri, 17 Nov 2000 19:18:51 -0500

I don't know whether this is a bug in CLISP or not, but I'm sending it
here becuse it at least concerns CLISP.                               
                                                                      
I'm trying to get the `trees' package from the CMU Lisp Repository to 
work under CLISP (it was originally written for CMU CL).  I can get it
to load into the interpreter fine (minus some warnings and name       
conflicts that sometimes happen and sometimes not).  The problem is   
when I try to invoke `compile-file' on one of the files.              
                                                                      
Trying to compile the file `binary-trees.lisp' from the distribution  
chokes on the following form:                                         
                                                                      
(defstruct (tree-node (:print-function tree-node-print)               
                                    (:conc-name tn-))                 
  content                                                             
  left                                                                
  right                                                               
  parent)                                                             
                                                                      
(apologies for the bad code formatting)                               
                                                                      
with the following error:                                             
                                                                      
*** - PRINT: Despite of *PRINT-READABLY*, #<TREE-NODE NIL #x202EE211> 
cannot be printed readably.                                           
                                                                      
And yes, that is supposed to be `Despite of'.                         
                                                                      
I don't know why such an error happens.  Can anybody offer suggestions
to why it happens and how to make it go away?  Thanks!                
                                                                      
-Nathan

---

From: Marco Antoniotti <[email-masked]>
Date: Sat, 18 Nov 2000 11:58:42 -0500

> Date: Fri, 17 Nov 2000 19:18:51 -0500
> From: Nathan Froyd <[email-masked]>
> Content-type: text/plain; charset=iso-8859-1
> User-Agent: IMHO/0.97.1 (Webmail for Roxen)
> Sender: [email-masked]
> X-BeenThere: [email-masked]
> X-Mailman-Version: 2.0beta5
> Precedence: bulk
> List-Id: CLISP user discussion <clisp-list.lists.sourceforge.net>
> Content-Length: 2434
> 
> cannot be printed readably.                     r                      
>                                                                       

Well, it is supposed to print unreadably.  The print function uses
PRINT-UNREADABLE-OBJECT after all.

I have a hunch that the problem might really be in the next form

   ;;;;;;;;;;;;; THIS SHOULD DISAPPEAR ;;;;;;;;;;;;;;;;;;;;

   (defparameter +null-node+ (make-tree-node))

Probaly there is an intercation with the CLisp compiler at some point.

You should be able to safely delete the declaration and change the
definition of TREE.  After all the sentinel and the root are
recomputed later.

This is very old code I wrote many years ago.  I have an "improved"
verion I use here and there.  Eventually it will make it into the
CLOCC.

Cheers

-- 
Marco Antoniotti =============================================================
NYU Bioinformatics Group			 tel. +1 - 212 - 998 3488
719 Broadway 12th Floor                          fax  +1 - 212 - 995 4122
New York, NY 10003, USA				 http://galt.mrl.nyu.edu/valis
             Like DNA, such a language [Lisp] does not go out of style.
			      Paul Graham, ANSI Common Lisp

---

From: Bruno Haible <[email-masked]>
Date: Mon, 20 Nov 2000 21:47:03 +0100 (CET)

Marco Antoniotti writes:

> > work under CLISP (it was originally written for CMU CL)

Duplicated work. Below are my patches.

> > cannot be printed readably.

This is because a defconstant form wants to save a TREE-NODE to the
fas file, but the print function is not defined in the compilation
environment. Use eval-when to fix this.

Bruno

============================================================================
(The diffs are "diffs -w", you cannot apply them through "patch".)

# Don't use the non-ANSI package CONDITIONS.
*** binary-trees-package.lisp	1999/04/22 09:35:08	1.1
--- binary-trees-package.lisp	1999/04/22 09:37:33	1.3
***************
*** 27,33 ****
  ;;; 12.26.1992: released.

! (defpackage "TREES" (:use "COMMON-LISP" "CONDITIONS")
    (:export make-tree
             tree-p
             size
--- 27,33 ----
  ;;; 12.26.1992: released.

! (defpackage "TREES" (:use "COMMON-LISP")
    (:export make-tree
             tree-p
             size

# Assume ANSI CL syntax for `define-condition' and `eval-when'.
# Don't redefine the CL function `copy-tree'.
# Define +null-node+ as a constant only once, otherwise clisp warns.
# Wrap the defstruct in eval-when-always: The defconstant initializer
  (make-tree-node) has to be evaluatable in the compilation environment.
*** binary-trees.lisp	1999/04/22 09:35:08	1.1
--- binary-trees.lisp	1999/05/01 20:42:52	1.6
***************
*** 251,258 ****
  ;;;============================================================================
  ;;; Prologue
  
! (eval-when #+CLtL2 (:compile-toplevel :load-toplevel)
!            #-CLtL1 (compile load)
    (unless (find-package "TREES")
      (load "binary-trees-package")))
  
--- 251,257 ----
  ;;;============================================================================
  ;;; Prologue
  
! (eval-when (:compile-toplevel :load-toplevel)
    (unless (find-package "TREES")
      (load "binary-trees-package")))
  
***************
*** 279,284 ****
--- 278,284 ----
  
  ;;; tree-node structure --
  
+ (eval-when (load compile eval)
  (defstruct (tree-node (:print-function tree-node-print)
                        (:conc-name tn-))
    content
***************
*** 286,306 ****
    right
    parent
    )
  ;;; tree-node --

  ;;; +null-node+ parameter -- The 'sentinel' used in various
  ;;; algorithms. It is defined as a parameter in order to redefine it
! ;;; for richer tree structures (e.g. red balck trees).
  
- #-:sentinel (defconstant +null-node+ (make-tree-node))
  (defconstant +null-node+ (make-tree-node))
  ;;; +null-node+ --

  ;;; tree structure --
  
! (defstruct (tree (:print-function tree-print))
    (name nil                     :type symbol)
    (root +null-node+             :type tree-node)
    (null-sentinel +null-node+    :type tree-node)
--- 286,306 ----
    right
    parent
    )
+ )
  ;;; tree-node --

  ;;; +null-node+ parameter -- The 'sentinel' used in various
  ;;; algorithms. It is defined as a parameter in order to redefine it
! ;;; for richer tree structures (e.g. red black trees).
  
  (defconstant +null-node+ (make-tree-node))
  ;;; +null-node+ --

  ;;; tree structure --
  
! (defstruct (tree (:copier nil) (:print-function tree-print))
    (name nil                     :type symbol)
    (root +null-node+             :type tree-node)
    (null-sentinel +null-node+    :type tree-node)
***************
*** 323,329 ****
  ;;; empty-error condition --
  
  (define-condition empty-error (simple-error)
!   (a-tree)
    (:report
     (lambda (cnd strm)
       (format strm
--- 323,329 ----
  ;;; empty-error condition --
  
  (define-condition empty-error (simple-error)
!   ((a-tree :initarg :a-tree :reader empty-error-a-tree))
    (:report
     (lambda (cnd strm)
       (format strm

# Don't use the non-ANSI package CONDITIONS.
# Ensure package "TREES" exists.
*** rbtrees-package.lisp	1999/04/22 09:35:08	1.1
--- rbtrees-package.lisp	1999/04/22 09:47:17	1.4
***************
*** 26,33 ****
  ;;; History:
  ;;; 12.26.1992: released.

! (defpackage "RED-BLACK-TREES" (:use "COMMON-LISP" "CONDITIONS" "TREES")
    (:nicknames "RB-TREES" "RBT")
    (:export make-tree
             tree-p
--- 26,36 ----
  ;;; History:
  ;;; 12.26.1992: released.
  
+ (eval-when (:compile-toplevel :load-toplevel)
+   (unless (find-package "TREES")
+     (load "binary-trees-package")))
  
! (defpackage "RED-BLACK-TREES" (:use "COMMON-LISP" "TREES")
    (:nicknames "RB-TREES" "RBT")
    (:export make-tree
             tree-p

# Assume ANSI CL syntax for `define-condition' and `eval-when'.
# Before loading binary-trees, must load binary-trees-package.

*** rbtrees.lisp	1999/04/22 09:35:08	1.1
--- rbtrees.lisp	1999/05/01 20:35:24	1.4
***************
*** 210,219 ****
  ;;;============================================================================
  ;;; Prologue
  
! (eval-when #+CLtL2 (:compile-toplevel :load-toplevel)
!            #-CLtL2 (compile load)
             (unless (find-package "TREES")
!              (load "binary-trees-package"))
             (unless (find-package "RED-BLACK-TREES")
               (load "rbtrees-package")))
  
--- 210,219 ----
  ;;;============================================================================
  ;;; Prologue
  
! (eval-when (:compile-toplevel :load-toplevel)
             (unless (find-package "TREES")
!              (load "binary-trees-package")
!              (load "binary-trees"))
             (unless (find-package "RED-BLACK-TREES")
               (load "rbtrees-package")))
  
***************
*** 296,302 ****
  ;;; empty-error condition --
  
  (define-condition empty-error (simple-error)
!   (a-tree)
    (:report
     (lambda (cnd strm)
       (format strm
--- 296,302 ----
  ;;; empty-error condition --
  
  (define-condition empty-error (simple-error)
!   ((a-tree :initarg :a-tree :reader empty-error-a-tree))
    (:report
     (lambda (cnd strm)
       (format strm