"is" and ==

S

Steve Holden

Warren said:
No you didn't. Your original post was a reply to a message whose subject
line was 'Re: "is" and ==', and included the header

In-Reply-To: <[email protected]>

You're right, thanks.
I think the fundamental mistake you have made is to convince yourself that
c[:]()

is legal Python. It isn't, it never has been.

In my opinion, it is better to ask me directly what I think than to assume
what I am thinking. Describing a situation in second person -- using "you"
-- tends to have more interpretation than fact. When the interpretation is
wrong, the person who is at the receiving end of that "you" may be compelled
to reply. Sometimes that correction includes another "you"; interpretation
spawns interpretation -- soon, facts are replaced by projectiles.
Well I don't think there's much chance of that here. Please accept my
apologies if I misunderstood you.
In summation:
I started this thread asking why c[:]() wouldn't work
I did not hijack another thread
I posted working examples (with one typo, not quoted here)
I am extremely annoyed by this post

Tis best not to assume what other people are thinking
Probably best not to try to help them too, if this is the response.

I do appreciate your help. Responding on topic helps. Negative feedback
regarding typos helps. And, your statement:

> Perhaps you didn't express yourself too clearly.

makes me feel all warm and fuzzy like ... why thank you!
Well clearly I'd rather you were responsible for the miscommunication
than I, but I don't *have* to be right about everything. And mostly I
try to help.
Agreed. Fortunately, others got the gist of what I was saying.

Oddly enough, as annoying as it was, your post helped my form, while other
posters have helped my content. I bet you'd make a good editor.

Cheers,

\~/
Sorry to have annoyed you. I don't always get up people's noses. Glad my
remarks were of at least *some* assistance.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
------------------ Asciimercial ---------------------
Get on the web: Blog, lens and tag your way to fame!!
holdenweb.blogspot.com squidoo.com/pythonology
tagged items: del.icio.us/steve.holden/python
All these services currently offer free registration!
-------------- Thank You for Reading ----------------
 
W

Warren Stringer

As mentioned a while back, I'm now predisposed towards using `do(c)()`
because square brackets are hard with cell phones. The one mitigating factor
for more general use, outside of cell phones, is speed. If a PEP enables a
much faster solution with c[selector()]() then it may be worthwhile. But, I
feel a bit circumspect about suggesting a change as I haven't looked at
Python source, nor have I looked at the BNF, lately. I think Martelli's
recent post on implantation may be relevant:
Tuples are implemented as compact arrays of pointer-to-PyObject (so are
lists, BTW). So, for example, a 10-items tuple takes 40 bytes (plus a
small overhead for the header) on a 32-bit build, not 80 as it would if
implemented as a linked list of (pointer-to-object, pointer-to-next)
pairs; addressing sometuple[N] is O(1), NOT O(N); etc, etc.

The questions about implementing a working c[:]() are:
1) Does it break anything?
2) Does it slow anything down?
3) Could it speed anything up?
4) Does it make code easier to read?
5) What question(s) did I forget to ask?

1) No? The fact that c() currently fails on a container implies that
enabling it would not break existing client code. Would this break the
language definition? A couple years ago, I hand transcribed the BNF of
version 2.2 to an alternative to BNF. I would love to know if c[:]() would
break the BNF in a fundamental way.

2) I don't know. I've always assumed that Python objects are hash table
entries. How would this change? Would it change? Does the message
"TypeError: 'list' object is not callable" guarantee a short path between
bytecode and hash table? Is there some other mitigating factor?

3) Maybe? Does overriding __call__ create any extra indirection? If yes,
then I presume that `do(c)()` would be slower the `c[:]()`. I am writing
rather amorphous code. This may speed it up.

4) I posit yes. Am I missing something? What idiom does would c[:]() break?
This correlates with whether `c[:]()` breaks the language definition, in
question 1)

Warren said:
I'm still a bit new at this, was wondering why c[:]() doesn't work, and
implicitly wondering why it *shouldn't* work.

It does work. It means "make a sliced copy of `c`, and then call it
with no arguments." Functionally that is _no different_ from `c()`,
which means "take `c` and call it with no arguments," because presuming
`c` is a list, `c[:]` makes a shallow copy.

So if you think `c()` and `c[:]()` should do something different in this
case, you are profoundly confused about Python's semantics of what
objects are, what it means to shallow copy a list, and what it means to
make a function call. That you keep including the slice suggests that
there's something about its meaning that's not yet clicking.

I use `c[:]()` because it is unambiguous about using a container
If you really want syntax where a function call on a container calls all
of its elements, then that is trivially easy to do by creating such an
object and overriding its `__call__` method.

If you're not willing to do that, but still insisting that `c[:]()`
makes sense, then perhaps it would be more advisable to learn more about
Python rather than try to suggest profound changes to the language and
its conventions.

You're right. At the same time, version 3 is coming up soon. There is a
short window of opportunity for profound changes.

Also, my audacious suggestion has spawned illuminating replies. For this
instance, I have read about shallow copy, before, but haven't been told
where it is used, before now. Other posts led to insights about closures,
and yielding a real solution. This is incredibly useful. I've learned a lot.

Thanks,

\~/
 
S

Steve Holden

Warren said:
As mentioned a while back, I'm now predisposed towards using `do(c)()`
because square brackets are hard with cell phones. The one mitigating factor
for more general use, outside of cell phones, is speed. If a PEP enables a
much faster solution with c[selector()]() then it may be worthwhile. But, I
feel a bit circumspect about suggesting a change as I haven't looked at
Python source, nor have I looked at the BNF, lately. I think Martelli's
recent post on implantation may be relevant:
Tuples are implemented as compact arrays of pointer-to-PyObject (so are
lists, BTW). So, for example, a 10-items tuple takes 40 bytes (plus a
small overhead for the header) on a 32-bit build, not 80 as it would if
implemented as a linked list of (pointer-to-object, pointer-to-next)
pairs; addressing sometuple[N] is O(1), NOT O(N); etc, etc.

The questions about implementing a working c[:]() are:
1) Does it break anything?
2) Does it slow anything down?
3) Could it speed anything up?
4) Does it make code easier to read?
5) What question(s) did I forget to ask?

1) No? The fact that c() currently fails on a container implies that
enabling it would not break existing client code. Would this break the
language definition? A couple years ago, I hand transcribed the BNF of
version 2.2 to an alternative to BNF. I would love to know if c[:]() would
break the BNF in a fundamental way.

2) I don't know. I've always assumed that Python objects are hash table
entries. How would this change? Would it change? Does the message
"TypeError: 'list' object is not callable" guarantee a short path between
bytecode and hash table? Is there some other mitigating factor?

3) Maybe? Does overriding __call__ create any extra indirection? If yes,
then I presume that `do(c)()` would be slower the `c[:]()`. I am writing
rather amorphous code. This may speed it up.

4) I posit yes. Am I missing something? What idiom does would c[:]() break?
This correlates with whether `c[:]()` breaks the language definition, in
question 1)

Warren said:
I'm still a bit new at this, was wondering why c[:]() doesn't work, and
implicitly wondering why it *shouldn't* work.
It does work. It means "make a sliced copy of `c`, and then call it
with no arguments." Functionally that is _no different_ from `c()`,
which means "take `c` and call it with no arguments," because presuming
`c` is a list, `c[:]` makes a shallow copy.

So if you think `c()` and `c[:]()` should do something different in this
case, you are profoundly confused about Python's semantics of what
objects are, what it means to shallow copy a list, and what it means to
make a function call. That you keep including the slice suggests that
there's something about its meaning that's not yet clicking.

I use `c[:]()` because it is unambiguous about using a container
Unfortunately nothing in your proposal addresses the issue that the
container object needs to contain only callable objects.

The general rule in Python is that you provide the right objects and
expect error tracebacks if you do something wrong. So I don't really see
why you feel it's necessary to "[be] unambiguous about using a
container" when you don't appear to feel the same about its containing
only functions.
If you really want syntax where a function call on a container calls all
of its elements, then that is trivially easy to do by creating such an
object and overriding its `__call__` method.

If you're not willing to do that, but still insisting that `c[:]()`
makes sense, then perhaps it would be more advisable to learn more about
Python rather than try to suggest profound changes to the language and
its conventions.

You're right. At the same time, version 3 is coming up soon. There is a
short window of opportunity for profound changes.
Which closed at the end of April as far as PEPs affecting the initial
implementation of version 3 was concerned. The python3000 and
python-ideas lists are the correct forum for those issues, though you
will of course get all sorts of opinions on c.l.py.
Also, my audacious suggestion has spawned illuminating replies. For this
instance, I have read about shallow copy, before, but haven't been told
where it is used, before now. Other posts led to insights about closures,
and yielding a real solution. This is incredibly useful. I've learned a lot.
That's good.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
------------------ Asciimercial ---------------------
Get on the web: Blog, lens and tag your way to fame!!
holdenweb.blogspot.com squidoo.com/pythonology
tagged items: del.icio.us/steve.holden/python
All these services currently offer free registration!
-------------- Thank You for Reading ----------------
 
G

Grant Edwards

As mentioned a while back, I'm now predisposed towards using
`do(c)()` because square brackets are hard with cell phones.

Yet you insist on adding gratuitous instances of [:] in your
code. Methinks you're being disingenuous.
The one mitigating factor for more general use, outside of
cell phones, is speed. If a PEP enables a much faster solution
with c[selector()]() then it may be worthwhile. But, I feel a
bit circumspect about suggesting a change as I haven't looked
at Python source, nor have I looked at the BNF, lately. I
think Martelli's recent post on implantation may be relevant:
Tuples are implemented as compact arrays of
pointer-to-PyObject (so are lists, BTW). So, for example, a
10-items tuple takes 40 bytes (plus a small overhead for the
header) on a 32-bit build, not 80 as it would if implemented
as a linked list of (pointer-to-object, pointer-to-next)
pairs; addressing sometuple[N] is O(1), NOT O(N); etc, etc.

The questions about implementing a working c[:]() are:

Again, _why_ the [:] ???
1) Does it break anything?

Not if you do it in a class of your own.
2) Does it slow anything down?
3) Could it speed anything up?
4) Does it make code easier to read?
5) What question(s) did I forget to ask?

1) No? The fact that c() currently fails on a container
implies that enabling it would not break existing client
code.

No, it doesn't. I can think of several cases where somebody
might depend on the fact that lists and tuples are not
callable. It's quite common in Python to write a function that
accepts a variety of argument types (e.g. accepting either a
file object or a file name). It's not unimaginable that
somebody might write a fuction that will accept either a
function or a list and expect that a list isn't callable.

[Please quit saying "a container" if you mean lists and tuples.
"A container" is way too general. There most probably _are_
containers for which c() does not fail.]
Would this break the language definition?

That depends on what you mean by "a container". If it's a
container class that you or somebody else wrote, then no, it
doesn't break the language definition. If you mean the builtin
list or tuple types, then yes, it breaks the language
definition because the language is currently defined such that
lists and tuples aren't callable.
A couple years ago, I hand transcribed the BNF of version 2.2
to an alternative to BNF. I would love to know if c[:]() would
break the BNF in a fundamental way.

No, the syntax is fine. It's just that the containers you seem
to have chosen don't do what you want.

For pete's sake, use one that does.
2) I don't know. I've always assumed that Python objects are
hash table entries. How would this change? Would it change?
Does the message "TypeError: 'list' object is not callable"
guarantee a short path between bytecode and hash table? Is
there some other mitigating factor?

I don't see why you think this has to be built into the
language when it would only take a few lines of code to define
such a class. IIRC, somebody already has. Your problem has
been solved for you. The whole point of having user-defined
classes/types is so that the language doesn't have to have
built-in every conceivable data type and behavior that anybody
will ever want.
So if you think `c()` and `c[:]()` should do something
different in this case, you are profoundly confused about
Python's semantics of what objects are, what it means to
shallow copy a list, and what it means to make a function
call. That you keep including the slice suggests that there's
something about its meaning that's not yet clicking.

I use `c[:]()` because it is unambiguous about using a
container

That makes no sense.
If you really want syntax where a function call on a container
calls all of its elements, then that is trivially easy to do
by creating such an object and overriding its `__call__`
method.

If you're not willing to do that, but still insisting that
`c[:]()` makes sense, then perhaps it would be more advisable
to learn more about Python rather than try to suggest profound
changes to the language and its conventions.

You're right. At the same time, version 3 is coming up soon.
There is a short window of opportunity for profound changes.

Also, my audacious suggestion

The suggestion that containers broadcast a "call" operation
isn't audacious. It's not going to happen, but there's nothing
wrong with the suggestion.

You just choose to write a lot of audacious nonsense along with
it.
 
W

Warren Stringer

Steve Holden Wrote
The general rule in Python is that you provide the right objects and
expect error tracebacks if you do something wrong. So I don't really see
why you feel it's necessary to "[be] unambiguous about using a
container" when you don't appear to feel the same about its containing
only functions.

Give that everything is a first class object

"Look ma! I'm an object"() # causes
Traceback (most recent call last) ...
TypeError: 'str' object is not callable

def funky(): lookma()
funky() # causes

Traceback (most recent call last)...
NameError: global name 'lookma' is not defined

Means that any exception can be caught, thus equal.

`c[:]()` is unambiguous because:

def c(): print 'yo'

c() # works, but
c[:]() # causes:

Traceback (most recent call last)...
c[:]() # causes:
TypeError: unsubscriptable object

There are many `c()` to be found in the wild and no `c[:]()`, thus
unambiguous. To be honest, I wasn't sure, until testing this, just now.

Which closed at the end of April as far as PEPs affecting the initial
implementation of version 3 was concerned. The python3000 and
python-ideas lists are the correct forum for those issues, though you
will of course get all sorts of opinions on c.l.py.

Oh well. Perhaps I can relax and actually write functioning code ;-)
What do you mean by 'c.l.py' ? The first thing that comes to mind is
'clippy' that helpful little agent in Word that helped pay for Simonyi's
trip into space.

Ching ching,

Warren
 
G

Grant Edwards

Oh well. Perhaps I can relax and actually write functioning
code ;-) What do you mean by 'c.l.py'?

comp.lang.python: the Usenet news group in which this
discussion is taking place.
 
E

Erik Max Francis

Warren said:
As mentioned a while back, I'm now predisposed towards using `do(c)()`
because square brackets are hard with cell phones. The one mitigating factor
for more general use, outside of cell phones, is speed.

The speed at which you can type code is almost _never_ a valid reason to
make something brief. Code gains readability from verbosity. (That can
be taken too far, of course, but that certainly doesn't apply here.)

Either way, something like `do(c)()` to do what you want is easily
implementable in Python, and always has been. Same thing with your
`c()` or `c[:]()` solutions (though the latter makes no semantic sense);
just use custom sequence types.
The questions about implementing a working c[:]() are:
1) Does it break anything?
2) Does it slow anything down?
3) Could it speed anything up?
4) Does it make code easier to read?
5) What question(s) did I forget to ask?

You keep sticking the slice in there. That still makes no sense.

The fundamental reason it does not make logical sense to make a list
callable (which would then call its elements) is that lists can contain
objects that aren't callable. So then, if you want lists to be
callable, the question becomes, what should it do with the elements that
aren't callable? Choke on the first one? Ignore them? Abort entirely
and not call any of them?

This kind of a design question can go every possible way depending on
what particular application you're using the calling syntax for, so the
proper design question from a language perspective is not to choose any.
If you want a callable sequence (which calls its elements and has any
or all of the above behaviors), it is _trivial_ to make one. There is
no need for support for this, because what it should do is not clear.
I use `c[:]()` because it is unambiguous about using a container

There are containers that don't support slicing (a stack, for instance),
so you're not using the right terminology here. If you do mean general
containers, then your slicing violates duck typing since it effectively
enforces a constraint that may not be desired. _If_ one were to have
callable containers, then callable containers should be usable in _any_
context in which an object is called, not just ones where slices were done.

If you intend `c[:]()` to have different semantics than `c()` -- it
isn't clear from your comments whether you mean it to or not, but you
keep nonsensically mentioning the slicing notation -- then you're
_really_ out in left field. Now that requires operations to behave
differently in different contexts, which is a huge can of worms and
rapidly makes code unreadable.

In short, your repeated use of `c[:]()` indicates a fundamental
misunderstanding about Pythonic style _and_ substance.
If you're not willing to do that, but still insisting that `c[:]()`
makes sense, then perhaps it would be more advisable to learn more about
Python rather than try to suggest profound changes to the language and
its conventions.

You're right. At the same time, version 3 is coming up soon. There is a
short window of opportunity for profound changes.

Soon isn't all that soon. Furthermore, it is very unlikely that someone
is going to be able to suggest profound and useful changes to Python
without first being familiar with it. So stabbing in the dark is not
going to be very constructive for either learning Python, or suggesting
useful improvements. That's just the way the ball bounces, unfortunately.
 
E

Erik Max Francis

Warren said:
`c[:]()` is unambiguous because:

def c(): print 'yo'

c() # works, but
c[:]() # causes:

Traceback (most recent call last)...
c[:]() # causes:
TypeError: unsubscriptable object

There are many `c()` to be found in the wild and no `c[:]()`, thus
unambiguous. To be honest, I wasn't sure, until testing this, just now.
>>> c = 'not quite'
>>> c[:] 'not quite'
>>> c[:]()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: 'str' object is not callable

You also seem to be under the impression that `x[:]()` is somehow
special syntax that is treated differently than `y = x[:]; y()`. It is not.

Besides, _ambiguity_ was never the problem. _Functionality_ is the problem.
 
W

Warren Stringer

Warren said:
The speed at which you can type code is almost _never_ a valid reason to
make something brief. Code gains readability from verbosity. (That can
be taken too far, of course, but that certainly doesn't apply here.)

There is code that you type which persists and code that you type from a
command line. Two completely different idioms. A credo inside the cell phone
game industry is that you lose half your audience with each menu keystroke.
That's how precious keystrokes are.

What may be confusing is speaking about both idioms at once.

In short, your repeated use of `c[:]()` indicates a fundamental
misunderstanding about Pythonic style _and_ substance.

Please define Pythonic. Is this like a certain US senator who defined porn
as "I know it when I see it."

28 years ago, I wrote a hierarchical DBMS that used lexical indentation. 15
years ago I wrote a multimedia script language that used lexical indentation
and automatic garbage collection - it was deployed on millons of clients. 2
years ago I hand coded every line of the Python 2.2 BNF into another style
of language description. Up until last month, I had tokenized a subset of
said definition in C++, using templates to manage cardinality. Recently, I
decided to forgo the C++ parser and am now rewriting it in Python. This is a
risk. So, what hoop does one jump though to earn that oh so coveted
"pythonic" merit badge?

Your other post responds with working examples. So, I'll jump over to that
one.
 
W

Warren Stringer

Warren said:
`c[:]()` is unambiguous because:

def c(): print 'yo'

c() # works, but
c[:]() # causes:

Traceback (most recent call last)...
c[:]() # causes:
TypeError: unsubscriptable object

There are many `c()` to be found in the wild and no `c[:]()`, thus
unambiguous. To be honest, I wasn't sure, until testing this, just now.
c = 'not quite'
c[:] 'not quite'
c[:]()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: 'str' object is not callable


Interesting example. By extension
#-------------------------Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'bad' is not defined
#-------------------------

Both your example and mine show well formed and ill formed statements at the
command line.
You also seem to be under the impression that `x[:]()` is somehow
special syntax that is treated differently than `y = x[:]; y()`. It is
not.

No; I was under the impression that `x[:]()` didn't work and the reason why
it didn't work wasn't obvious.

I like your use case. Am I correct in assuming that `y = x[:]; y()` is NOT
to be found in working code? If that is the case, then nothing gets broken.
It would be instructive to have a use case where enabling c[:]() would break
existing code.
Besides, _ambiguity_ was never the problem. _Functionality_ is the
problem.

Ambiguity is one of many parameters. It was a problem with another poster. I
wish I had McConnel's Code Complete book handy. Let's see ... a search
yields: debugging, testing, performance, portability, design, interfaces,
style, and notation.

My use case is this:

do(orchestra(score)).pickle()
do(orchestra(conductor)).sequence()

And so now, that I can, I am happy. Life is good. Time to sleep.
 
M

Marc 'BlackJack' Rintsch

Warren Stringer said:
I like your use case. Am I correct in assuming that `y = x[:]; y()` is NOT
to be found in working code? If that is the case, then nothing gets broken.
It would be instructive to have a use case where enabling c[:]() would break
existing code.

What does "enabling c[:]()" mean? Do you expect after "enabling it"
``c()`` and ``c[:]()`` to be different for the same list or tuple `c`?
My use case is this:

do(orchestra(score)).pickle()
do(orchestra(conductor)).sequence()

This isn't a use case unless you also say what the involved objects are
and what semantic you expect from this source snippet. Just guessing,
but might the following do what you want without the need to make lists
and tuples callable?

def do(iterable, func):
for item in iterable:
func(item)

do(orchestra(score), pickle)
do(orchestra(conductor), sequence)

Ciao,
Marc 'BlackJack' Rintsch
 
M

Marc 'BlackJack' Rintsch

Warren Stringer said:
The speed at which you can type code is almost _never_ a valid reason to
make something brief. Code gains readability from verbosity. (That can
be taken too far, of course, but that certainly doesn't apply here.)

There is code that you type which persists and code that you type from a
command line. Two completely different idioms. A credo inside the cell phone
game industry is that you lose half your audience with each menu keystroke.
That's how precious keystrokes are.

What may be confusing is speaking about both idioms at once.

In short, your repeated use of `c[:]()` indicates a fundamental
misunderstanding about Pythonic style _and_ substance.

Please define Pythonic. Is this like a certain US senator who defined porn
as "I know it when I see it."

Yes you are right, "pythonic" is not a hard fact. But one indicator is
consistency and no surprising behavior if possible. And that your
insisting on ``c[:]()`` instead of just ``c()`` seems to indicate you want
a change that is quite surprising. It would mean that a slice of a list
returns an other type with the __call__ method implemented.
28 years ago, I wrote a hierarchical DBMS that used lexical indentation. 15
years ago I wrote a multimedia script language that used lexical indentation
and automatic garbage collection - it was deployed on millons of clients. 2
years ago I hand coded every line of the Python 2.2 BNF into another style
of language description. Up until last month, I had tokenized a subset of
said definition in C++, using templates to manage cardinality. Recently, I
decided to forgo the C++ parser and am now rewriting it in Python. This is a
risk. So, what hoop does one jump though to earn that oh so coveted
"pythonic" merit badge?

Grok The Zen of Python (``import this`` at the interpreter prompt)?
Write "pythonic" code?

I don't see how writing other languages and Python parsers and translators
into other representations tells you much about the spirit and idiomatic
*usage* of a language. Your proposal is not about syntax, it's about
semantics. ``obj[:]()`` is basically syntactic sugar for:
``obj.__getitem__(slice(None)).__call__()`` and you want a change in the
implementation of `list.__getitem__()` and `tuple.__getitem__()`.

Ciao,
Marc 'BlackJack' Rintsch
 
D

Duncan Booth

Grant Edwards said:
[Please quit saying "a container" if you mean lists and tuples.
"A container" is way too general. There most probably _are_
containers for which c() does not fail.]

One example of such a container is any folderish content in Zope:
subscripting gets you the contained pages, calling renders the default
view.
 
C

Carsten Haese

There is code that you type which persists and code that you type from a
command line. Two completely different idioms. A credo inside the cell phone
game industry is that you lose half your audience with each menu keystroke.
That's how precious keystrokes are.

Then why do have your users typing code into a cell phone?
 
G

Grant Edwards

I like your use case. Am I correct in assuming that `y = x[:];
y()` is NOT to be found in working code?

No, you may not assume that.
If that is the case, then nothing gets broken. It would be
instructive to have a use case where enabling c[:]() would
break existing code.

I've already explained such a use case.

You still seem to be operating under the delusion that c[:] is
somehow different than c.
 
D

dackz

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.

I want to call every object in a tupple, like so:

#------------------------------------------
def a: print 'a'
def b: print 'b'
c = (a,b)
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?
 
W

Warren Stringer

And that your
insisting on ``c[:]()`` instead of just ``c()`` seems to indicate you want
a change that is quite surprising. It would mean that a slice of a list
returns an other type with the __call__ method implemented.

I am not insisting on anything. I use ``c[:]()`` as shorthand way of saying
"c() for c in d where d is a container"

Having c() support containers seems obvious to me. It jibes with duck
typing. Perhaps the title of this thread should have been: "Why don't
containers quack?"

A change is surprising only if it breaks something. I still haven't seen any
code that breaks by making such a change. Seeing such code would teach a
great deal.
> Grok The Zen of Python (``import this`` at the interpreter prompt)?

I think this is incredibly cool.
Write "pythonic" code?

Probably not yet; I'm still learning - I have yet to perfect my silly walk.
http://grampyshouse.net/cliches/images/sillywalk.jpg
 
W

Warren Stringer

[Please quit saying "a container" if you mean lists and tuples.
"A container" is way too general. There most probably _are_
containers for which c() does not fail.]

One example of such a container is any folderish content in Zope:
subscripting gets you the contained pages, calling renders the default
view.

Cool. Could you point me to some example code?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,157
Latest member
MercedesE4
Top