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

From: Ken Anderson <kanderso_at_bbn.com>
Date: Mon, 12 Jul 1999 18:30:07 -0400

This would work as long as you didin't expect to use (set!) to side effect a slot.

At 03:05 PM 7/12/1999 -0700, Brian Denheyer wrote:
>>>>>> "Lars" == Lars Thomas Hansen <lth_at_ccs.neu.edu> writes:
>
> Lars> An old Pascal hand, eh?
>
>No, just lazy ;-) But now I am intrigued. I'll have to go dig up a
>Pascal book and find out where this is used.
>
> Lars> I think that if you're willing to make a smallish concession in the
> Lars> convenience of your syntax it should be straightforward, regardless of
> Lars> the underlying technology. It's easy, for example, to expand
>
>And what would that concession be ? Something like :
>
>(let ((z 22))
> (with-slots self (x y)
> (+ z (* x y))))
>
>?
>
> Lars> (let ((z 22))
> Lars> (with-object self (x y)
> Lars> (+ z (* x y))))
>
> Lars> into the code above, that is, you name the slots you want. (Note,
> Lars> "easy" using a low-level macro system; the R5RS macro system can't
> Lars> splice identifiers.)
>
>It _is_ easy to expand it when it contains hints, but I was hoping
>that I could use it exactly as I originally wrote, i.e. there would be
>no "hints" as to which slots were being accessed. If there are no
>"hints" provided then the system must look at each identifier as it
>encounters it and checks the active object to see if it is a
>slot-name. I want this to be efficient too, so such checks should
>only happen once at "compile time".
>
> Lars> I might even mutter that WITH-SLOTS is a better name for this construct
> Lars> than WITH-OBJECT.
>
>I might mutter agreement :-)
>
>BTW I did some looking around and found that Elk has a with-instance
>form which supplies this functionality. It appears that it creates a
>micro-environment, the instance environment, which is used for the
>variable name lookup. Even though it is a macro, there is low-level
>implementation support happening.
>
>So here is a WAAWT (wild-*ss-attempt-without-testing) for the version
>with "hints" :
>
>(define-syntax with-slots
> (syntax-rules ()
> ((with-object obj (name ...) body1 ...)
> ((let ((name (slot-ref obj name)) ...)
> body1 ...)))))
>
>Should work, right ? I have no idea how to do this with define-macro.
>I like R5RS macros much more better. Somewhere around here i have the
>stk and r5rs howto, i.e. old code I put together to use r5rs macros
>with stk via slib.
>
>Brian
>
>
>
Received on Tue Jul 13 1999 - 00:31:14 CEST

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