Thanks, 

A most lucid explanation.

-- Michael

On Wed, 2003-10-22 at 11:00, Marco Antoniotti wrote:
> 
> 
> On Monday, Oct 20, 2003, at 22:51 America/New_York, Michael Naunton 
> wrote:
> 
> >
> > I want to write something like the following (it defines s struct, and
> > gets some efficient compilation hints from s1.lisp...)
> >
> > (load "s1.lisp")
> 
> Here you are in package *PACKAGE* (let's say it is "COMMON-LISP-USER")
> 
> >
> > (defstruct s1
> >   (a))
> >
> > (defun ref (a b)
> >   "This is the function I am trying to optimize"
> >   (list "ref" a b))
> 
> This definition creates the function  CL-USER::REF
> 
> >
> > (defun test1 (x)
> >   "fast form."
> >   (declare (type s1 x))
> >   (ref x "a"))
> >
> > (defun test2 (x)
> >   "slow form (punt)"
> >   (ref x "a"))
> >
> > (compile 'test1)
> > (compile 'test2)
> >
> > (defun x ()
> >   (let ((v (make-s1)))
> >     (setf (s1-a v) 12)
> >     (list
> >      (test1 v)
> >      (test2 v))))
> >
> >
> > Where s1.lisp looks something like:
> >
> > (in-package "C") ;; needed for continuation stuff
> >
> 
> Exactly.  Now you are in package "C"
> 
> 
> 
> > (defknown ref (t t) t)
> 
> .... and you are telling the compiler that C::REF is known.
> 
> >
> > (deftransform ref ((x y) (s1 t) t)
> >   "With a known string (y) convert to a slot accessor."
> >   (unless (constant-continuation-p y)
> >     (give-up))
> >   (let ((acc (read-from-string (format nil "~sl-~a" (continuation-value
> > y)))))
> >     `(,acc x)))
> 
> .... same here.  You are defining a transform for C::REF
> 
> 
> 
> >
> > However, defknown/deftransform don't find my hints...
> >
> > *(x)
> > (("ref" #S(s1 :a 12) "a") ("ref" #S(s1 :a 12) "a"))
> >
> > I can dump everything into the wrong (C) package and get the effect I
> > want:
> >
> > (in-package "C")
> >
> 
> .... now you are in package "C"
> 
> > (defstruct s1
> >   (a))
> >
> > (defun ref (a b)
> >   (list "ref" a b))
> 
> .... and you are defining C::REF
> 
> 
> >
> > (defknown ref (t t) t)
> >
> > (deftransform ref ((x y) (s1 t) t)
> >   (unless (constant-continuation-p y)
> >     (give-up))
> >   (let ((acc (read-from-string (format nil "s1-~a" (continuation-value
> > y)))))
> >     `(,acc x)))
> >
> > (defun test1 (x)
> >   (declare (type s1 x))
> >   (ref x "a"))
> >
> > (defun test2 (x)
> >   (ref x "a"))
> >
> > (compile 'test1)
> > (compile 'test2)
> >
> > (defun x ()
> >   (let ((v (make-s1)))
> >     (setf (s1-a v) 12)
> >     (list
> >      (test1 v)
> >      (test2 v))))
> >
> >
> > * (in-package :c)
> > * (x)
> > (12 ("ref" #S(s1 :a 12) "a"))
> >
> > Obviously, I have a basic misconception here.  What am I doing wrong?
> 
> Did the above help?  Try to use fully qualified names to see where 
> things may go wrong.
> Another fix would be to declare
> 
> (in-package "C")
> 
> (defknown cl-user::ref (t t) t)
> 
> (deftransform cl-user::ref ......)
> 
> Cheers
> 
> Marco
> 
> 
> 
> --
> Marco Antoniotti
> NYU Courant Bioinformatics Group              tel. +1 - 212 - 998 3488
> 715 Broadway 10th FL                          fax. +1 - 212 - 998 3484
> New York, NY, 10003, U.S.A.
> 
> 



Reply via email to