{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

20090323-VisitorTrace

20090323-VisitorTrace - How do visitors work This set of...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
How do visitors work? This set of slides traces through the execution of a visitor we‟ve seen before (the lengthVisitor) on a short list. It shows how the runtime stack makes recursion possible. First let‟s recall: how the visitor is defined – how „execute‟ is defined in the two list state classes
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Length visitor in the empty case the answer is zero in the non-empty case the answer is one more than the length of the rest of the list public Integer emptyCase(LRStruct<?> host, Object _){ return 0; } public Integer nonEmptyCase(LRStruct<?> host, Object _){ return 1 + host.getRest().execute(this,_); }
Background image of page 2
„execute‟ definition in states Empty state: public Object execute(LRS host, IAlgo algo, Object argut){ return algo.emptyCase(host, input); } NonEmpty state: public Object execute(LRS host, IAlgo algo, Object argut){ return algo.nonEmptyCase(host, input); }
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon