c[:]()

dackz dackze at gmail.com
Fri Jun 1 11:50:27 EDT 2007


This discussion has gone in more circles than Earth has gone 'round
the Sun, but it seems you should consider the following:

1) Sequences and functions serve fundamentally different purposes in
Python. One is for containing objects, the other is for executing an
action. (And yes, I'm aware that these concepts can differ in other
contexts. But we're talking about Python.)

2) It seems--at least to me--a bit dubious to change an entire general
purpose programming language to suit a very limited--and frankly
strange--use case.

3) You'd probably be better off making a very simple and concise
domain specific language.

You could do whatever you want with syntax--in the case of a cell
phone, I would think the less punctuation you have, the better. Your
main goal seems to be speed or ease of input, so perhaps a very
abbreviated syntax would be more important than being able to read the
code as if it were English, as is the case in Python--the tradeoff
here being more time spent reading documentation and more time spent
learning syntax. You also might stand to benefit from this move if you
ever decide to implement this software in something other than Python.

Specifically, not requiring parentheses for function calls would
probably be a nice start, and very short built-in names might also be
helpful. Again, this is a tradeoff between readability and speed of
input.

You'd also have to spend more time implementing a parser of some sort.
This could very well outweigh any benefits involved, depending on your
time frame.

But to reiterate the most obvious point: in your context, [:] is just
notation for copying a sequence, so c[:]() would have *exactly* the
same effect as c(). If it helps, you can think of [:] being just like
writing .copy() for dictionaries: it makes a shallow copy, nothing
more. Now think about that while remembering that sequences and
functions serve different purposes in Python and thus have different
semantics. There's a reason this isn't implemented in Python: it would
be confusing beyond belief at first sight. And there's already
perfectly good syntax for this: "for func in funcs: func()"

Being able to write code quickly on a cell phone is not a goal of
Python. That's your goal.

On 5/30/07, Warren Stringer <warren at muse.com> wrote:
> I want to call every object in a tupple, like so:
>
> #------------------------------------------
> def a: print 'a'
> def b: print 'b'
> c = (a,b)
>
> >>>c[:]()  # i wanna
>  TypeError: 'tupple' object is not callable
>
> >>>c[0]()  # expected
> a
> >>>c[:][0] # huh?
> a
> >>> [i() for i in c] # too long and ...huh?
> a
> b
> [None,None]
> #------------------------------------------
>
> Why? Because I want to make Python calls from a cell phone.
> Every keystroke is precious; even list comprehension is too much.
>
> Is there something obvious that I'm missing?



More information about the Python-list mailing list