Implicit conversion to boolean in if and while statements

Rick Johnson rantingrickjohnson at gmail.com
Mon Feb 11 08:13:58 EST 2013


On Monday, February 11, 2013 6:40:23 AM UTC-6, Chris Angelico wrote:
> [...]
> Or doing what you were pointing and laughing at Pike for, and using
> two-symbol delimiters. You could even make it majorly logical:
> 
> list_ = [[ 1, 2, 3 ]]
> tuple_ = ([ 1, 2, 3 ])
> dict_ = [{ 1, 2, 3 }]
> frozendict_ = ({ 1, 2, 3 })
> set_ = [< 1, 2, 3 >]
> frozenset_ = (< 1, 2, 3 >)

I am vehemently against using more than one "opening seq char" and one "closing seq char". It works fine for single depth sequences, however, once you start nesting the mental focus required to parse the doubled openers/closers is headache inducing. I would accept wrapping the literal in some sort of declaration though, something like i proposed earlier in the thread. The easiest is to use:

  set({1,2,3})

but that looks like a function call! So we'd need a unique syntax. Either a single tag like:

  set{1,2,3}

Or we could use start and end tags like:

  set{1,2,3}set

where "set{" and "}set" are delimiters. For lists, tuples, and dict we would use the short form because these literals are far too ubiquitous:

  [1,2,3] # list
  {k:v} # dict
  (1,2,3) # tuple

However, the grouping chars for tuples has always been confusing because they can clash with grouping of expressions. What is this?

  (1)

It's NOT a tuple! But it looks like a tuple! What is this:

  1,2

it IS a tuple, but it does not look like a tuple! 

That's an unfortunate side effect of a poorly thought-out tuple syntax. 



More information about the Python-list mailing list