On Mon, Aug 23, 2010 at 6:35 PM, Dhananjay Nene <dhananjay.n...@gmail.com> wrote: > On Mon, Aug 23, 2010 at 4:26 PM, Rajeev J Sebastian < > rajeev.sebast...@gmail.com> wrote: > >> Probably better to use PEAK Rules.... >> >> Regards >> Rajeev J Sebastian >> > > That looks much more fully featured indeed. But I couldn't understand why > features such as the one I "copy-pasted" below are relevant when a simple > lambda is all that is required : > > > - The Basic AST > Builder<http://peak.telecommunity.com/DevCenter/PEAK-Rules/AST-Builder>and > advanced Code > > Generation<http://peak.telecommunity.com/DevCenter/PEAK-Rules/Code-Generation> > - Criteria <http://peak.telecommunity.com/DevCenter/PEAK-Rules/Criteria>, > Indexing <http://peak.telecommunity.com/DevCenter/PEAK-Rules/Indexing>, > and > Predicates<http://peak.telecommunity.com/DevCenter/PEAK-Rules/Predicates> > - Syntax pattern > matching<http://peak.telecommunity.com/DevCenter/PEAK-Rules/Syntax-Matching>
When you have a large number of rules, you want to optimize the dispatcher to select the most appropriate rule in the fastest possible way. In your case, only the result of the 'ticket' method is ever used for the dispatch; imagine if different methods had different conditions altogether. For e.g.: @when("product.days_since_last_sale > days(365)") def discount(product, user): return "10%" @when("product.category == 'football' and user.is_football_lover") def discount(product, user): return "50%" @when("product.category == 'cricket'") def discount(product, user): return "0%" etc. Regards Rajeev J Sebastian _______________________________________________ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers