From: Greg Menke
Subject: defmethod vs declare
Date: 
Message-ID: <m38zhsamks.fsf@europa.mindspring.com>
Hi all,

I was wondering if the Lispworks compiler in specific (or "lisp
compilers" in general) can or do automatically optimize code dealing
with specialized parameters in defmethods.  My guess is they would not
in order to keep things consistent.  Is this correct?

Thanks,

Greg

From: Jochen Schmidt
Subject: Re: defmethod vs declare
Date: 
Message-ID: <9in5ct$jkde8$1@ID-22205.news.dfncis.de>
Greg Menke wrote:

> 
> Hi all,
> 
> I was wondering if the Lispworks compiler in specific (or "lisp
> compilers" in general) can or do automatically optimize code dealing
> with specialized parameters in defmethods.  My guess is they would not
> in order to keep things consistent.  Is this correct?

I'm not sure but I think some compilers seem to do such optimizations...
AFAIR LispWorks seems to do this - but no warranty on that!
In what way would it not be consistent?
The compiler can trust on the fact that a method will only be applied when
it's parameter types are right.

ciao,
Jochen
From: Greg Menke
Subject: Re: defmethod vs declare
Date: 
Message-ID: <m3wv5cyyjn.fsf@europa.mindspring.com>
Jochen Schmidt <···@dataheaven.de> writes:


> > I was wondering if the Lispworks compiler in specific (or "lisp
> > compilers" in general) can or do automatically optimize code dealing
> > with specialized parameters in defmethods.  My guess is they would not
> > in order to keep things consistent.  Is this correct?
> 
> I'm not sure but I think some compilers seem to do such optimizations...
> AFAIR LispWorks seems to do this - but no warranty on that!
> In what way would it not be consistent?
> The compiler can trust on the fact that a method will only be applied when
> it's parameter types are right.

My thought was if the user did not supply declares, a compiler might
choose to not automatically optimize; essentially leaving the issue of
optimizing or not up to the user.  

Of course I speak from ignorance, not being aware of the subtle
tradeoffs in optimization vs safety- so automatic optimizations on
specialized parameters might not impose significant risk anyhow.

Gregm
From: Jochen Schmidt
Subject: Re: defmethod vs declare
Date: 
Message-ID: <9ip5eh$k1he9$1@ID-22205.news.dfncis.de>
Greg Menke wrote:

> Jochen Schmidt <···@dataheaven.de> writes:
> 
> 
>> > I was wondering if the Lispworks compiler in specific (or "lisp
>> > compilers" in general) can or do automatically optimize code dealing
>> > with specialized parameters in defmethods.  My guess is they would not
>> > in order to keep things consistent.  Is this correct?
>> 
>> I'm not sure but I think some compilers seem to do such optimizations...
>> AFAIR LispWorks seems to do this - but no warranty on that!
>> In what way would it not be consistent?
>> The compiler can trust on the fact that a method will only be applied
>> when it's parameter types are right.
> 
> My thought was if the user did not supply declares, a compiler might
> choose to not automatically optimize; essentially leaving the issue of
> optimizing or not up to the user.
> 
> Of course I speak from ignorance, not being aware of the subtle
> tradeoffs in optimization vs safety- so automatic optimizations on
> specialized parameters might not impose significant risk anyhow.

The compiler may decide to optimize method-calls if e. g SPEED is higher 
than SAFETY in an OPTIMIZE proclamation. So the user could again decide 
what to do.

ciao,
Jochen
From: Greg Menke
Subject: Re: defmethod vs declare
Date: 
Message-ID: <m3sng0yygc.fsf@europa.mindspring.com>
"Wade Humeniuk" <········@cadvision.com> writes:


> I came across of example of LispWorks compiling a defmethod and appearing to
> be trying some optimization for slot access in structs passed as parameters.
> 
> See attached file, first evaluate the buffer and then try to compile the
> buffer in the editor.  An error is signalled for a non-exsistent slot in the
> compilation case.

I confess I don't know how to deal with the attached buffer.  How was
it encoded?

Thanks,

Greg
From: Wade Humeniuk
Subject: Re: defmethod vs declare
Date: 
Message-ID: <9ioosj$3c8$1@news3.cadvision.com>
> I confess I don't know how to deal with the attached buffer.  How was
> it encoded?

Encoded?  Here is the file in the text.

Wade

;; Start

(defstruct interval-leaf)

(defstruct (interval-run (:include interval-leaf))
  (type nil)
  (repeats nil)
  (distance nil)
  (time nil)
  (pace nil))

(defstruct (interval-rest (:include interval-leaf))
  (time nil))

(defmethod interval-node-print-string ((leaf interval-rest))
  (with-slots (time no-slot) leaf
    (with-output-to-string (str)
      (write-string time str)
      (write-string no-slot str)
      (write-string " Pause" str))))

;; End
From: Thomas F. Burdick
Subject: Re: defmethod vs declare
Date: 
Message-ID: <xcvr8vkaui8.fsf@famine.OCF.Berkeley.EDU>
"Wade Humeniuk" <········@cadvision.com> writes:

> > I confess I don't know how to deal with the attached buffer.  How was
> > it encoded?
> 
> Encoded?  Here is the file in the text.

Last time it was uuencoded.  Greg: That's an obsolete unix method for
encoding 8-bit/byte files into a format that can be sent over e-mail
and usenet.  Most unix systems have `uuencode' and `uudecode', though
there are some widespread implementations that are mutually
incompatible.  Which is part of why uuencoding is obsolete.  Most
people use the mime facilities that provide the equivalent
functionality.
From: Tim Bradshaw
Subject: Re: defmethod vs declare
Date: 
Message-ID: <ey3y9pr7tin.fsf@cley.com>
> Last time it was uuencoded.  Greg: That's an obsolete unix method for
> encoding 8-bit/byte files into a format that can be sent over e-mail
> and usenet.  

Strangely enough it was posted with a MS news reader.

--tim
From: Wade Humeniuk
Subject: Re: defmethod vs declare
Date: 
Message-ID: <9ipjqt$a5j$1@news3.cadvision.com>
"Tim Bradshaw" <···@cley.com> wrote in message
····················@cley.com...
>
> > Last time it was uuencoded.  Greg: That's an obsolete unix method for
> > encoding 8-bit/byte files into a format that can be sent over e-mail
> > and usenet.
>
> Strangely enough it was posted with a MS news reader.

 Yes MS Outlook Express 5.

Checked out its options seetings.  Yes encoding was set to uuencode, changed
it Mime.  Thanks for the feedback.

Wade
From: Greg Menke
Subject: Re: defmethod vs declare
Date: 
Message-ID: <m3zoa7fwaq.fsf@europa.mindspring.com>
> (defstruct interval-leaf)
> 
> (defstruct (interval-run (:include interval-leaf))
>   (type nil)
>   (repeats nil)
>   (distance nil)
>   (time nil)
>   (pace nil))
> 
> (defstruct (interval-rest (:include interval-leaf))
>   (time nil))
> 
> (defmethod interval-node-print-string ((leaf interval-rest))
>   (with-slots (time no-slot) leaf
>     (with-output-to-string (str)
>       (write-string time str)
>       (write-string no-slot str)
>       (write-string " Pause" str))))
> 
> ;; End

> I came across of example of LispWorks compiling a defmethod and appearing to
> be trying some optimization for slot access in structs passed as parameters.
> 
> See attached file, first evaluate the buffer and then try to compile the
> buffer in the editor.  An error is signalled for a non-exsistent slot in the
> compilation case.


CLTL indicates with-slot's behavior is undefined if a slot doesn't
exist.  Could that be the basis for the differing behavior between
interpreted and compiled tests?


But I don't think I was able to duplicate your example, when I ran
interpreted I got the following;


CL-USER 9 > (setf x (make-interval-rest))
#S(interval-rest time nil)

CL-USER 10 > (setf (interval-rest-time x) (format nil "~A" pi))
"3.141592653589793"

CL-USER 11 > (interval-node-print-string x)

Error: The slot no-slot is missing in #S(interval-rest time "3.141592653589793"), #<structure-class interval-rest 213F6EF4>, when slot-valueing nil,nil.
  1 (abort) Return to level 0.
  2 Return to top loop level 0.

Type :b for backtrace, :c <option number> to proceed,  or :? for other options





I was unable to sucessfully compile, Lispworks giving me the
following;

**++++ Error in (method interval-node-print-string (interval-rest)): 
  The slot clos::effective-slots is unbound in the object #<structure-class interval-rest 213F6EF4> (an instance of class #<standard-class structure-class 205E36A4>).
; (top-level-form 2)
; *** 1 error detected, no fasl file produced.

---- Done ----
From: Tim Bradshaw
Subject: Re: defmethod vs declare
Date: 
Message-ID: <ey3u20f7shi.fsf@cley.com>
* Greg Menke wrote:

> I was wondering if the Lispworks compiler in specific (or "lisp
> compilers" in general) can or do automatically optimize code dealing
> with specialized parameters in defmethods.  My guess is they would not
> in order to keep things consistent.  Is this correct?

I think a compiler is entitled to do any optimisation it would have
done in the context of an equivalent (DECLARE (TYPE ...)).  After all
within the method body you know that the declaration is true - you
wouldn't have got there otherwise.

Lots of systems optimise things like SLOT-VALUE, and at least one
(Genera) can optimise accessors in method bodies to be very quick.  I
expect more recent implementations can do similar tricks.

--tim