I'm coming from Tcl-world ...

Andreas Leitgeb Andreas.Leitgeb at siemens.at
Mon Aug 5 14:15:30 CEST 2002


Cameron Laird <claird at starbase.neosoft.com> wrote:
> Part of the context of Andreas' questions
> is that Tcl builds-in a [switch] with
> several different comparisons possible.
Yes, Cameron knows me from comp.lang.tcl :-)

For tcl's switch, I can specify any of: exact-, glob- or regexp-match,
which is technically speaking, syntactic sugar for an if-elif*-else
construct, but really very good quality sugar, that I'm sorry to 
miss here.

The quality of that sugar comes from not having to explicitely repeat
the comparison-function and common 'switchvar' argument. 
Now that I write this, I suddenly see, how one can resemble a switch 
almost cleanly with lambda-expressions and if-elif*-else:
  switchvar=...
  # "compare"  could be regexp,glob,case-insensitive
  case=lambda x: compare(x,switchvar) 
  if case('foo'):
    ...
  elif case('foo*'):
    ...
you get the idea ...
I'm just curious about performance ...

-- 
Newsflash: Sproingy made it to the ground !
  read more ... <http://avl.enemy.org/sproingy/>



More information about the Python-list mailing list