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

From: Lars Thomas Hansen <lth_at_ccs.neu.edu>
Date: Mon, 12 Jul 1999 16:54:07 -0400

Brian Denheyer <briand_at_deldotd.com> writes:

>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.

An old Pascal hand, eh?

>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 ?

I think that if you're willing to make a smallish concession in the
convenience of your syntax it should be straightforward, regardless of
the underlying technology. It's easy, for example, to expand

  (let ((z 22))
    (with-object self (x y)
      (+ z (* x y))))

into the code above, that is, you name the slots you want. (Note,
"easy" using a low-level macro system; the R5RS macro system can't
splice identifiers.)

I might even mutter that WITH-SLOTS is a better name for this construct
than WITH-OBJECT.

--lars
Received on Mon Jul 12 1999 - 22:55:14 CEST

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