Jump to page: 1 2
Thread overview
foreach/opApply is the visitor pattern
Jan 30, 2009
BCS
Jan 31, 2009
Lars Ivar Igesund
Jan 31, 2009
BCS
Feb 01, 2009
Robert Fraser
Feb 01, 2009
BCS
Feb 01, 2009
grauzone
Feb 01, 2009
BCS
Feb 01, 2009
grauzone
Feb 13, 2009
Spacen Jasset
January 30, 2009
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
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
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
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
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
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
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
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
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
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".


« First   ‹ Prev
1 2