Re: possible to write a with-object prc/macro ?

From: Ken Anderson <kanderso_at_bbn.com>
Date: Mon, 12 Jul 1999 17:26:31 -0400

At 01:31 PM 7/12/1999 -0700, Brian Denheyer wrote:
>
>
>I find myself doing the following quite a lot :
>
>(define-method foo
> ((self <obj>))
> (let ((x (x-of self)) ;; actually named slot 'x'
> (y (y-of self)) ;; actually named slot 'y'
> ...)
> calculations using x, y ...
>
>It would be very convenient to have something like :
>
>(with-object self
> calculation involving slot-x,slot-y and variables OTHER than x and y.
>
>so I could write
>
>(define-method foo
> ((self <obj>))
> (let ((z 22))
> (with-object self
> (+ z (* x y)))))
>
>and it would do the right thing, i.e. take x and y from self.
>Naturally if x and y are not slots, then it would throw and error for
>unknown variable.
>
>It's not obvious to me that something like this could be written as a
>macro, i.e. would it require low-level modifications to the
>implementation ?

Lar's suggestion is like the (with-slots) macro in Common Lisp. It requires mentioning the slot names explictly, which makes it clear where the variable is coming from.

If you don't want to mention the fields, you need to have
(define-method) and (with-object) work together. You also need compile time access to fields of the class.

Flavors methods had direct access to slots by name, which occasionally lead to confusion. From years of writing Lisp, even with-slots got too verbose, so i just use the accessors directly in most cases:

(define-method foo ((self <obj>))
  (let ((z 22))
     (+ z (* (x-of self) (y-of self)))))

In many cases (with-slots) doesn't save you that much typing.
Received on Mon Jul 12 1999 - 23:27:36 CEST

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST