From: Mirko
Subject: Is this method macro wicked or what?
Date: 
Message-ID: <05fb599c-332a-469e-b3ea-f2108cebd285@z9g2000yqi.googlegroups.com>
I recently adapted one of Doug Hoyt's macros (see letoverlambda.com)
to allow me to eliminate the (with-slots ...):

(defclass circle ()
  ((r)
   (a)))

(defmethod/s! area ((this circle))
  (setf s!a (* 2 pi s!r)))


In other words, instead of using (with-slots ...), in the method body,
I prepend the slot variables by s!.  The macro parses the body,
identifies those, and builds a defmethod with a symbol-macrolet block
around the body that expands the tagged symbols into a (slot-
value ...).

I find it helpful to specify a bit more about the variable other than
just its role (which the name should do).  So, while having code
cluttered with s! might be annoying to some, it might be helpful for
others.

Anyway, here are the relevant macros (which depend on a few functions
from Graham):

;; adapted from Doug Hoyt: http://letoverlambda.com/lol.lisp
(defun s!-symbol-p (s)
  "Does the symbol start with `S!'?"
  (and (symbolp s)
       (> (length (symbol-name s)) 2)
       (string= (symbol-name s)
                "S!"
                :start1 0
                :end1 2)))



(defmacro defmethod/s! (name args &body body)
  "Build defmethod environment where every symbol prefixed with `s!'
is tagged as being a slot of the object that is defined in the first
argument of `args'.

After expansion, `body' is prepended by a `symbol-macrolet' block
where every s!symbol is defined as a (slot-value object symbol)."
  (let ((syms (remove-duplicates
                (remove-if-not #'s!-symbol-p
                               (onlisp:flatten body))))
	(this (caar args)))
    `(defmethod ,name ,args
       (symbol-macrolet ,(mapcar
			  (lambda (s)
			    `(,s (slot-value ,this
					     ',(onlisp:symb (subseq
						     (symbol-name s)
						     2)))))
			  syms)
         ,@body))))

Cheers,

Mirko

From: Pascal J. Bourguignon
Subject: Re: Is this method macro wicked or what?
Date: 
Message-ID: <878wnr7kvt.fsf@galatea.local>
Mirko <·············@gmail.com> writes:

> I recently adapted one of Doug Hoyt's macros (see letoverlambda.com)
> to allow me to eliminate the (with-slots ...):
>
> (defclass circle ()
>   ((r)
>    (a)))
>
> (defmethod/s! area ((this circle))
>   (setf s!a (* 2 pi s!r)))
>
> [...]
>
> (defmacro defmethod/s! (name args &body body)
>   "Build defmethod environment where every symbol prefixed with `s!'
> is tagged as being a slot of the object that is defined in the first
> argument of `args'.


What do you think this should do:

(defmethod/s! binary ((left class-1) (right class-2))
   (setf (s!r right) (s!l left)))


I find this defmethod/s! greatly insufficient.


-- 
__Pascal Bourguignon__
From: Alex Mizrahi
Subject: Re: Is this method macro wicked or what?
Date: 
Message-ID: <49a844cd$0$90266$14726298@news.sunsite.dk>
 PJB> What do you think this should do:

 PJB> (defmethod/s! binary ((left class-1) (right class-2))
 PJB>    (setf (s!r right) (s!l left)))

 PJB> I find this defmethod/s! greatly insufficient.

about 90% (*) of methods work mainly with object in first parameter,
so this thing is just a shorthand notation for a frequent case.

*: also note that 63.7% of all statistics is made up. 
From: Mirko
Subject: Re: Is this method macro wicked or what?
Date: 
Message-ID: <217277e6-6c5c-48f8-bb1d-124fa8aa9938@j38g2000yqa.googlegroups.com>
On Feb 27, 2:53 pm, "Alex Mizrahi" <········@users.sourceforge.net>
wrote:
>  PJB> What do you think this should do:
>
>  PJB> (defmethod/s! binary ((left class-1) (right class-2))
>  PJB>    (setf (s!r right) (s!l left)))
>
>  PJB> I find this defmethod/s! greatly insufficient.
>
> about 90% (*) of methods work mainly with object in first parameter,
> so this thing is just a shorthand notation for a frequent case.
>
> *: also note that 63.7% of all statistics is made up.

Both of you have a point regarding the limitations and usage.

Accepting the limitations, or even designing a notation & macro to
deal with them, then define font-locking in emacs so that object slots
clearly stand out in the method (by color or font).

Given what the economy is, I may have time on my hands to implement
that :-)

Mirko