This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: CL implementation questions


On 04/13/2012 11:38 AM, Charles Turner wrote:
Thanks for the explanation Helmut.

On 9 April 2012 07:25, Per Bothner<per@bothner.com> wrote:
Yes.  Common Lisp uses colon for a package prefix of a compound symbol,
and it's unclear how that should interact with colon notation or other
short-hands.  I suggest using the procedures invoke and invoke-static,
rather
than using colon notation.  We might consider some kind of abbreviated
syntax for Common Lisp, but let's not worry about that for now.

The reason I feel I need this is in a definition for CAR. The Scheme version is currently:

(define (car x)
   (if (eq? x '()) x ((as<pair>  x):getCar)))

I should be able to simulate that by creating a new lexical scope for DECLARE:

(defun car (x)
   (if (null x) nil (let () (declare (pair x)) (invoke x 'getCar))))

This seems quite nasty, it's worse because DECLARE currently doesn't
work properly in this case. It sets the type of declaration X to PAIR
before runtime IIUC, so this version of CAR rejects inputs like '()
because they're not of type PAIR.

Technically this may be allowed by the Common Lisp spec (and even do what you need), but let's try the simpler case first with a separate variable:

(defun car (x)
(if (null x) nil (let ((xp x)) (declare (pair xp)) (invoke xp 'getCar))))


I suggest implementing CL "the" expression:

(defun car (x)
    (if (null x) nil (invoke (the pair x) 'getCar)))

Clearly the simple-minded approach in Lisp2Compilation#processTypeDeclArgs of:

decl = this.lexical.get(var);
decl.setType(this.exp2Type((Pair) typeList));
decl.setFlag(Declaration.TYPE_SPECIFIED);

is not correct.

Nope, but it may get you started.


I get the feeling that I'm over-complicating the issue, but it seems
like I need to create "ghost aliases" for each new lexical scope for
use by DECLARE, so that it can reliably modify the extent of a
variable. I'm sorry for making up jargon, by "ghost alias", I mean
fudging Compilation#current_scope so that it holds alias declarations
from further up the static chain. This seems expensive, horrible,
simple-minded, etc, but I really don't know how else to get things
like this working:

(defun test (x)
   (if #t
       x
       (let ()
         (declare (integer x))
         x)))

A "ghost alias" seems a plausible solution. It may not be quite matching the letter of the CL spec.

One version of the ghost alias is an implicit local variable
initialized to the outer variable.  This is inexpensive, though
there may be problems if there is an assignment in the inner scope.
In that case a more complex aliasing scheme may be needed.
However, that seems unimportant enough that I'd be satisfied
if we emitted a warning.



(test 10.4) ; Value: 10.4

The current behavior is
(test 10.4)
; Type error, expecting INTEGER, found DFLONUM.

I also found that scoping was quite broken with my previous patch,
calling super.rewrite_body was a bad idea, I was getting results like:

(let ((x 10)) (display x) (let ((x 20)) (display x)) (display x))
;Value: 10 20 20

For reasons I can only attribute to magic.

It might be worthwhile to try to figure out why that happened.


Avoiding the calls to super
by completely overriding the rewrite_body fixed this, but my soul will
be forever damned by the refactoring community, since  I had to change
a few private methods to protected ones in order to shoehorn the
change in.

Changing private methods to protected is a perfectly reasonable thing to do
when you need to generalize some code between previously foreseen uses.
I'm somewhat more concerned about the seeming code duplication, but I haven't
had time to really evaluate it.
--
--Per Bothner
per@bothner.com http://per.bothner.com/



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]