Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Binding problem with 'do

From: tim:johnsons-web at: 31-Jul-2005 14:26

* Ladislav Mecir <[lmecir--mbox--vol--cz]> [050731 14:04]:
> Tim Johnson napsal(a): > > ... > > > That's almost pythonistic in it's engineering (from me that's a > > complement) :-). However, if I understand you correctly, it would > > be as large and repetitive as the original switch. > > > > > ... > > If that is the case, then it is highly probable, that the design issue > is deeper than you presented and the solution should be more complex. I > have some code that solves such issues in a more elegant way (using > associative arrays e.g.), but that is a "higher level" solution, i.e. it > was possible only when I knew the actual problem more thoroughly than > you described in your question.
I spend (roughly) equal times in python and rebol. After being up to my elbows in python, it is always refreshing to get back to rebol, but when I switch from rebol to python, I find myself enjoying python dictionaries, both the explicit ones and the builtin _dict_ structures. # Example: explicit def do_sql(name,layout): dispatch = { 'radio':kbLists.do_sql_radio(), 'text':kbLists.do_sql_text(), 'textarea':kbLists.do_sql_textarea(), 'decimal':kbLists.do_sql_decimal(), 'uinteger':kbLists.do_sql_uinteger(), 'select':kbLists.do_sql_select(), 'date':kbLists.do_sql_date(), 'checkbox':kbLists.do_sql_checkbox(), 'password':kbLists.do_sql_text(), } return ' %s %s,' % (name,dispatch[layout['type']]) # Example: using builtin _dict_ in class constructor def __init__(self, url='', text='', **kw): self.target = None self.onClick = None self.onMouseOver = None self.onMouseOut = None self.url = url self.text = text # target ... text constitutue self.__dict__ when they are # preceded by 'self.' for item in kw.keys(): if self.__dict__.has_key(item): self.__dict__[item] = kw[item] else: raise KeyError, `item`+' not a valid parameter for this class.' I've written an associative list context for rebol but it is very simple and does not well employ rebol's reflective and self-composing features. I seldom use it directly but from another context. I have found that sometimes when you use examples of another language in a specific language forum, some might protest, but for me, it is oftentimes productive to work out a solution in one language and translate to another. In the days of slower processors, python was often used to prototype code that was then translated to C or C++, or so it did advertise itself. Tim -- Tim Johnson <[tim--johnsons-web--com]> http://www.alaska-internet-solutions.com