[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Underpinnings of Method Wrapping

Peter

11/30/2003 11:25:00 PM

2 Answers

T. Onoma

12/1/2003 3:19:00 AM

0

On Monday 01 December 2003 12:25 am, Peter wrote:
> > wrap foo(*args)
> > # set a here, do other stuff not affecting the super call
> > result = psudeo_super
> > # use a here, do other stuff not affecting the result
> > end
> >
> > Then we don't need pre or post. I suppose if no "psuedo_super" is given
> > it would be assumed to be like a pre? I'm not sure. What do you think?
>
> First a note: I think intrinsic and extrinsic got swapped between the
> first mention of it and now. Maybe we should try to get these things
> straight to avoid unnecessary misunderstandings. A wrap was intrinsic,
> because it was an intrinsic part of the semantics of a method, and pre and
> post were extrinsic because they were really just riding along quietly.
> That sounds logical to me. By this definition I assume above you meant
> extrinsic, right? We could also choose some other terms that are harder
> to mix up...

Sorry, source of confusion: I used 'wrap' here to mean a combined pre and
post. (Mentally, I'm still repeating def for an intrinsic wraps). Perhaps
better terms are: inner wrap and outer wrap? So with the above I was pointing
out that we could just have a separate keyword for outer wrap definitions.

> Now for pseudo_super; it looks a bit weird, but I haven't got any better
> idea yet. I'm toying with something like this:
>
> pdef foo(*args)
> pre
> a = something
> # blah
> post
> print a
> # blah2
> end
> end
>
> It's just that I want to get rid of the explicit call to super.

You're a man after my own heart! :-) I don't know if you noticed the research
notes at the bottom of the RCR, but this is essentially one of the notations
I was playing with and very much liked. Perfect for outer wraps. And pdef
actually works pretty well too, once you think about it for a sec. Short and
to the point.

> > Your right. Sorry. But I do think sime of the same basic methods apply.
> > Not sure. I guess I need some examples to really be able to consider.
>
> I think if we want to get AOP to Ruby, it won't hurt to have examples
> showing what it can do. For starters, we could search the AspectJ site for
> examples and see what they look like in Ruby. But for the main dish we
> probably need examples of our own to show the Full Potential. But I'm
> looking at a busy week now, but after that I'll have some time to give it
> a serious try.

That would be great, I have some other work to do too. So afterward, I take it
you want to collaborate on a finalized joint RCR on the matter? That would be
excellent. And yes, some good examples are quite important.

> > I think you're right on. My implementation, instead, just adds more of
> > the same:
>
> IMO, they both make sense. The existing version should use the
> redefinition syntax, your new version the wrapping syntax, agreed?

I think so. Could you clearify these two different syntaxes and where they
apply, so that I can be sure that I'm understanding you correctly?

-t0



T. Onoma

12/1/2003 1:04:00 PM

0

On Monday 01 December 2003 12:25 am, Peter wrote:
> First a note: I think intrinsic and extrinsic got swapped between the
> first mention of it and now. Maybe we should try to get these things
> straight to avoid unnecessary misunderstandings. A wrap was intrinsic,
> because it was an intrinsic part of the semantics of a method, and pre and
> post were extrinsic because they were really just riding along quietly.
> That sounds logical to me. By this definition I assume above you meant
> extrinsic, right? We could also choose some other terms that are harder
> to mix up...

I was thinking about the terms. To really distinguish these two types of wraps
for what they do I think the following terms, or similiar terms, would really
nail them down and prevent any confusion, and also help us think about them
better:

watch -or- monitor = extrinsic/outer wrap
submethod = intrinsic/inner wrap

Does this work for you?

Also I was wondering, how do we get the results of super with the following
code?

watch foo(*args)
    pre
      a = something
      # blah
    post
      print a
      # blah2
    end
  end

Note that I used watch instead of pdef just to see what it would look like. Of
course this notation also has the sticking point of what happens if pre and
post aren't given (error?) and also how does super wrapping fit into this?

Also, in thinking about the purpose of a "watch wrap" it occurs to me that it
could still potentially effect the object (eg. @a = x) which I'm thinking
should probably be beyond its "write scope". So perhaps it should be enclosed
in some sort of object-specifc read-only namespace? Kind of like Matz'
proposal:

http://www.rubyist.net/~matz/slides/rc2003/mgp...

But applicable to methods. In other words a "watch" should have access to the
global namespace, but only read access to the local object's namespace. So a
"watch wrap" is equivalent to a "submethod" using this kind of namespace
restriction:

(using my repeated definition syntax from the RCR)

def foo(*args)
namespace self
  a = something
    # blah
    r = escape { super }
    print a
    # blah2
end
end

Where 'namespace self' means that any effects on the object self, made within
the namespace are "rolled back" at the end. But 'escape' means the namespace
doesn't apply to what happens in its block.

This is a bit confusing, I know. Really just thinking out-loud here. I hope
the concepts I'm trying to convey make sense though.

-t0