CL implementation questions
Charles Turner
chturne@gmail.com
Fri Apr 13 18:38:00 GMT 2012
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.
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.
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)))
(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. 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.
Code attached.
Charles.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: declare.diff
Type: application/octet-stream
Size: 6327 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/kawa/attachments/20120413/8bd3cb4d/attachment.obj>
More information about the Kawa
mailing list