Thread overview | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
January 30, 2009 foreach/opApply is the visitor pattern | ||||
---|---|---|---|---|
| ||||
Correct me if I'm wrong but I thing that D's opApply is a form of the Visitor pattern where the calling function's stack frame is the visitor object. This just occurred to me. Maybe I've been missing something re the visitor pattern but I think this make for a nice, cool and easy way to describe it. (Also I don't remember it being described that way) |
January 30, 2009 Re: foreach/opApply is the visitor pattern | ||||
---|---|---|---|---|
| ||||
Posted in reply to BCS | On Fri, Jan 30, 2009 at 5:35 PM, BCS <ao@pathlink.com> wrote:
> Correct me if I'm wrong but I thing that D's opApply is a form of the Visitor pattern where the calling function's stack frame is the visitor object.
Yeah. As far as I know it is.
|
January 31, 2009 Re: foreach/opApply is the visitor pattern | ||||
---|---|---|---|---|
| ||||
Posted in reply to BCS | BCS wrote: > Correct me if I'm wrong but I thing that D's opApply is a form of the Visitor pattern where the calling function's stack frame is the visitor object. > > This just occurred to me. Maybe I've been missing something re the visitor pattern but I think this make for a nice, cool and easy way to describe it. (Also I don't remember it being described that way) Indeed, I heard it called that a long time ago, and have explained it as such since then. -- Lars Ivar Igesund blog at http://larsivi.net DSource, #d.tango & #D: larsivi Dancing the Tango |
January 31, 2009 Re: foreach/opApply is the visitor pattern | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lars Ivar Igesund | Hello Lars,
> BCS wrote:
>
>> Correct me if I'm wrong but I thing that D's opApply is a form of the
>> Visitor pattern where the calling function's stack frame is the
>> visitor object.
>>
>> This just occurred to me. Maybe I've been missing something re the
>> visitor pattern but I think this make for a nice, cool and easy way
>> to describe it. (Also I don't remember it being described that way)
>>
> Indeed, I heard it called that a long time ago, and have explained it
> as such since then.
>
Well I guess I just figured out how to cut the time it takes to explain by about 90%. Nifty. Maybe the docs should use the term.
|
February 01, 2009 Re: foreach/opApply is the visitor pattern | ||||
---|---|---|---|---|
| ||||
Posted in reply to BCS | BCS wrote:
> Correct me if I'm wrong but I thing that D's opApply is a form of the Visitor pattern where the calling function's stack frame is the visitor object.
>
> This just occurred to me. Maybe I've been missing something re the visitor pattern but I think this make for a nice, cool and easy way to describe it. (Also I don't remember it being described that way)
Er.... no. There's no double-dispatch (at least automatically), there's only one foreach body delegate. The visitor pattern as far as I know it uses dynamic dispatch so the visitor object can handle different objects in the class hierarchy differently. For example, you couldn't use a foreach to enumerate through a syntax tree and handle expressions and statements differently (well, you could, but you'd have to do it manually).
|
February 01, 2009 Re: foreach/opApply is the visitor pattern | ||||
---|---|---|---|---|
| ||||
Posted in reply to Robert Fraser | On Sun, Feb 1, 2009 at 7:10 AM, Robert Fraser <fraserofthenight@gmail.com> wrote:
> BCS wrote:
>>
>> Correct me if I'm wrong but I thing that D's opApply is a form of the Visitor pattern where the calling function's stack frame is the visitor object.
>>
>> This just occurred to me. Maybe I've been missing something re the visitor pattern but I think this make for a nice, cool and easy way to describe it. (Also I don't remember it being described that way)
>
> Er.... no. There's no double-dispatch (at least automatically), there's only one foreach body delegate. The visitor pattern as far as I know it uses dynamic dispatch so the visitor object can handle different objects in the class hierarchy differently. For example, you couldn't use a foreach to enumerate through a syntax tree and handle expressions and statements differently (well, you could, but you'd have to do it manually).
I don't know/think that's a requirement for the actual visitor pattern to work. I think it's mostly that iteration is turned inside-out.
|
February 01, 2009 Re: foreach/opApply is the visitor pattern | ||||
---|---|---|---|---|
| ||||
Posted in reply to Robert Fraser | Hello Robert,
> BCS wrote:
>
>> Correct me if I'm wrong but I thing that D's opApply is a form of the
>> Visitor pattern where the calling function's stack frame is the
>> visitor object.
>>
>> This just occurred to me. Maybe I've been missing something re the
>> visitor pattern but I think this make for a nice, cool and easy way
>> to describe it. (Also I don't remember it being described that way)
>>
> Er.... no. There's no double-dispatch (at least automatically),
> there's only one foreach body delegate. The visitor pattern as far as
> I know it uses dynamic dispatch so the visitor object can handle
> different objects in the class hierarchy differently. For example, you
> couldn't use a foreach to enumerate through a syntax tree and handle
> expressions and statements differently (well, you could, but you'd
> have to do it manually).
>
OK I'll grant that it doesn't follow the normal pattern to the letter but it can be viewed as a degenerate case where there is only one visitable type.
|
February 01, 2009 Re: foreach/opApply is the visitor pattern | ||||
---|---|---|---|---|
| ||||
Posted in reply to BCS | BCS wrote:
> Correct me if I'm wrong but I thing that D's opApply is a form of the Visitor pattern where the calling function's stack frame is the visitor object.
>
> This just occurred to me. Maybe I've been missing something re the visitor pattern but I think this make for a nice, cool and easy way to describe it. (Also I don't remember it being described that way)
More importantly, why does it matter?
|
February 01, 2009 Re: foreach/opApply is the visitor pattern | ||||
---|---|---|---|---|
| ||||
Posted in reply to BCS | BCS wrote:
> Hello Robert,
>
>> BCS wrote:
>>
>>> Correct me if I'm wrong but I thing that D's opApply is a form of the
>>> Visitor pattern where the calling function's stack frame is the
>>> visitor object.
>>>
>>> This just occurred to me. Maybe I've been missing something re the
>>> visitor pattern but I think this make for a nice, cool and easy way
>>> to describe it. (Also I don't remember it being described that way)
>>>
>> Er.... no. There's no double-dispatch (at least automatically),
>> there's only one foreach body delegate. The visitor pattern as far as
>> I know it uses dynamic dispatch so the visitor object can handle
>> different objects in the class hierarchy differently. For example, you
>> couldn't use a foreach to enumerate through a syntax tree and handle
>> expressions and statements differently (well, you could, but you'd
>> have to do it manually).
>>
>
> OK I'll grant that it doesn't follow the normal pattern to the letter but it can be viewed as a degenerate case where there is only one visitable type.
Does that mean all function calls are a degenerate case of the visitor pattern?
|
February 01, 2009 Re: foreach/opApply is the visitor pattern | ||||
---|---|---|---|---|
| ||||
Posted in reply to grauzone | Hello grauzone,
> BCS wrote:
>
>> Hello Robert,
>>
>>> BCS wrote:
>>>
>>>> Correct me if I'm wrong but I thing that D's opApply is a form of
>>>> the Visitor pattern where the calling function's stack frame is the
>>>> visitor object.
>>>>
>>>> This just occurred to me. Maybe I've been missing something re the
>>>> visitor pattern but I think this make for a nice, cool and easy way
>>>> to describe it. (Also I don't remember it being described that way)
>>>>
>>> Er.... no. There's no double-dispatch (at least automatically),
>>> there's only one foreach body delegate. The visitor pattern as far
>>> as I know it uses dynamic dispatch so the visitor object can handle
>>> different objects in the class hierarchy differently. For example,
>>> you couldn't use a foreach to enumerate through a syntax tree and
>>> handle expressions and statements differently (well, you could, but
>>> you'd have to do it manually).
>>>
>> OK I'll grant that it doesn't follow the normal pattern to the letter
>> but it can be viewed as a degenerate case where there is only one
>> visitable type.
>>
> Does that mean all function calls are a degenerate case of the visitor
> pattern?
>
no only when you pass a "action" memeber that is called on "stuff".
|
Copyright © 1999-2021 by the D Language Foundation