digitalmars.D.learn - foreach/opApply is the visitor pattern
- BCS (5/5) Jan 30 2009 Correct me if I'm wrong but I thing that D's opApply is a form of the Vi...
- Jarrett Billingsley (2/5) Jan 30 2009 Yeah. As far as I know it is.
- Lars Ivar Igesund (8/15) Jan 31 2009 Indeed, I heard it called that a long time ago, and have explained it as...
- BCS (3/16) Jan 31 2009 Well I guess I just figured out how to cut the time it takes to explain ...
- Robert Fraser (7/14) Feb 01 2009 Er.... no. There's no double-dispatch (at least automatically), there's
- Jarrett Billingsley (4/19) Feb 01 2009 I don't know/think that's a requirement for the actual visitor pattern
- BCS (3/21) Feb 01 2009 OK I'll grant that it doesn't follow the normal pattern to the letter bu...
- grauzone (2/9) Feb 01 2009 More importantly, why does it matter?
- Spacen Jasset (7/17) Feb 13 2009 Because there is a difference? opApply is more like a functor. Not the
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)
Jan 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.
Jan 30 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
Jan 31 2009
Hello Lars,BCS wrote: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.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.
Jan 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)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).
Feb 01 2009
On Sun, Feb 1, 2009 at 7:10 AM, Robert Fraser <fraserofthenight gmail.com> wrote:BCS wrote: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.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).
Feb 01 2009
Hello Robert,BCS wrote: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.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).
Feb 01 2009
BCS wrote:Hello Robert,Does that mean all function calls are a degenerate case of the visitor pattern?BCS wrote: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.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).
Feb 01 2009
Hello grauzone,BCS wrote:no only when you pass a "action" memeber that is called on "stuff".Hello Robert,Does that mean all function calls are a degenerate case of the visitor pattern?BCS wrote: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.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).
Feb 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?
Feb 01 2009
grauzone wrote:BCS wrote:Because there is a difference? opApply is more like a functor. Not the visitor pattern in my view of things. They are/can be used to solve different things. The visitor pattern commonly can be used to avoid case object.type: situations, to deal with different object types. Whereas a functor is used for other things, like iteration.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?
Feb 13 2009