Subject: [clisp-list] Re: Backquote problem.

From: Kaz Kylheku <[email-masked]>
Date: Wed Feb 25 13:02:11 2004

It has come to my attention that some Lisps allow this:

 `(x1 x2 ... xn . #(,y1 ,@y2 ...))

In other words, the backquote can be an improper list, whose trailing
atom contains an object with unquotes.

My backquote implementation rejects this because it's closely based on
the CLHS-suggested transformation of

  `(x1 x2 ... xn . atom) 

into

  (append [x1] [x2] ... [xn] (quote atom))

where the [] notation indicates a transformation to be done on the
items, not relevant to this issue. So it appears that the usage 
requires a diagnostic or is undefined behavior. What the implementation
does now is it leaves the pieces of unquote syntax in the atom, without
any diagnostic.

Nevertheless, if a trivial change is made in the code, so that the
translation is:

  (append [x1] [x2] ... [xn] (backquote atom))

then the expected behavior is produced which matches what some other
Lisps produce: the unquotes are reduced against the backquote and
everything is cool.

(Of course, the usage:

 `(x1 x2 ... xn . #(,y1 ,@y2 ...))

can be rewritten like this to explicitly propagate a backquote down to
the atom:

 `(x1 x2 ... xn . ,`#(,y1 ,@y2 ...))

which obtains the desired behavior without depending on undefined
syntax).

---

From: Sam Steingold <[email-masked]>
Date: Wed Feb 25 14:32:04 2004

> * Kaz Kylheku <[email-masked]> [2004-02-25 12:52:39 -0800]:
>

sounds good - please send a patch and a ChangeLog entry.

-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.honestreporting.com>
Time would have been the best Teacher, if it did not kill all its students.

---

From: Kaz Kylheku <[email-masked]>
Date: Mon Mar 8 14:30:04 2004

[I have to do more testing and provide a tiny test case that reproduces
this problem.]

Suppose you have a program that builds as a CLISP image, and you have a
feature in that program whereby it can regenerate itself using sources
and write a new image of itself.

When you repeatedly invoke this feature, you get a successively larger
and larger image, as reported by the figures printed by SAVEINITMEM.

This happens even though garbage collection is done just before calling
by calling (GC) just before (SAVEINITMEM).

In my program, I actually do a DELETE-PACKAGE before re-loading the
modules into the image, so that no symbolic references remain to any of
the top-level functions and variables. So the growth is not from things
like DEFVARS that still have old values, not replaced by the reloading.

---

From: Pascal J.Bourguignon <[email-masked]>
Date: Mon Mar 8 23:41:04 2004

> like DEFVARS that still have old values, not replaced by the reloading.

That's the problem!  You  believe there remain no symbolic references.
But  symbols are not  necessarily garbage  collected just  because you
delete their home package!

You  would have  to set  to nil  any place  that keep  a  reference to
anything  leading to  stuff  "inside"  the package  to  really get  it
garbage collected.

[52]> (defpackage :test)
#<PACKAGE TEST>
[53]> (defun test::fun (x) (format t "from test:fun: ~A~%" x))
TEST::FUN
[54]> (defparameter c (let ((x 42)) (lambda (z) (format t "from closure: ~A~%" z) (test::fun (incf x)))))
C
[55]> c
#<CLOSURE :LAMBDA (Z) (FORMAT T "from closure: ~A~%" Z) (TEST::FUN (INCF X))>
[56]> (funcall c 2)
from closure: 2
from test:fun: 43
NIL
[57]> (delete-package :test)
T
[58]> (funcall c 2)
from closure: 2
from test:fun: 44
NIL
[59]> (ext:gc)
886018
[60]> c
#<CLOSURE :LAMBDA (Z) (FORMAT T "from closure: ~A~%" Z) (#:FUN (INCF X))>
[61]> 

And of  course, all symbols (such  as symbols in  the deleted package)
referenced by the orphan function are still kept:

[66]> (symbol-function (first (fourth (function-lambda-expression c))))
#<CLOSURE #:FUN (X) (DECLARE (SYSTEM::IN-DEFUN #:FUN))
  (BLOCK #:FUN (FORMAT T "from test:fun: ~A~%" X))>

-- 
__Pascal_Bourguignon__                     http://www.informatimago.com/
There is no worse tyranny than to force a man to pay for what he doesn't
want merely because you think it would be good for him.--Robert Heinlein
http://www.theadvocates.org/