Re: spawning pyhon apps...

2009-01-09 Thread Mark Wooding
bruce wrote: > toying with an idea.. trying to figure out a good/best way to spawn > multiple python scripts from a parent python app. i'm trying to figure > out how to determine when all child apps have completed, or to > possibly determine if any of the child processes have died/halted.. You d

Re: why cannot assign to function call

2009-01-09 Thread Mark Wooding
Joe Strout wrote: > No, actually, that was me. rurpy's list was something like C, FORTRAN, > Perl, and VBA. My mistake -- I failed to read the quoting properly. Apologies to all. We still dealt with C. Fortran (to give it its modern spelling) has a similar data model to C, but passes argume

Re: why cannot assign to function call

2009-01-09 Thread Mark Wooding
Steven D'Aprano wrote: > Er, perhaps you missed that I was replying to Joe Strout. Yes, evidently. My apologies for the mix up! -- [mdw], who obviously should put the keyboard down now. -- http://mail.python.org/mailman/listinfo/python-list

Re: why cannot assign to function call

2009-01-10 Thread Mark Wooding
[Another tome. I hope this contains sufficient new material to continue to be of interest to other readers.] Steven D'Aprano wrote: > On Fri, 09 Jan 2009 20:23:11 +0000, Mark Wooding wrote: > > > No: not directly. The Python program deals solely with references; > > an

Re: why cannot assign to function call

2009-01-10 Thread Mark Wooding
ru...@yahoo.com wrote: > Agreed. I think the docs, especially those that develop > the conceptual model of how Python work at runtime, could > use some major attention. If we can achieve consensus in this (still remarkably civil) discussion, we might be able to amend the docs. > I would be wil

Re: why cannot assign to function call

2009-01-10 Thread Mark Wooding
ru...@yahoo.com wrote: > What is the observable difference between converting an > array to a reference (pointer) to that array and passing > the reference by value, and passing the array by reference? For one: #include static size_t foo(char v[]) { return sizeof v; } int main(void) { char

Re: why cannot assign to function call

2009-01-10 Thread Mark Wooding
Steven D'Aprano wrote: > There are actually three fundamental characteristics of pass-by-reference: > > * passing a value by reference does not lead to the value being copied, > in contrast with pass-by-value where it does; > > * modifications to the value passed by reference are visible to th

Re: why cannot assign to function call

2009-01-10 Thread Mark Wooding
Steven D'Aprano wrote: > I don't believe it is a red-herring. As I understand it, Mark and Joe > insist that C is pass-by-value *even in the case of arrays*, despite the > semantics of array passing being identical to the semantics of pass-by- > reference in (say) Pascal. But they aren't. I'

Re: why cannot assign to function call

2009-01-11 Thread Mark Wooding
ru...@yahoo.com wrote: > Mark Wooding wrote: > > ru...@yahoo.com wrote: > > > >> What is the observable difference between converting an > >> array to a reference (pointer) to that array and passing > >> the reference by value, and passi

Re: why cannot assign to function call

2009-01-11 Thread Mark Wooding
Aaron Brady wrote: > True or not, it requires the reader to know what references are. And, > since your definition conflicts with the C++ definition, it's not > clear that the requirement is good. I blame C++ for coopting a perfectly good word with a established well-understood meaning, and app

Re: why cannot assign to function call

2009-01-11 Thread Mark Wooding
Steven D'Aprano wrote: > I guess this is where you explain again that arrays in C are "bizarre", > and that while "int arr[2]" inside a function body means "declare an > array of two ints and call it 'arr'", the exact same declaration in a > function parameter list means something else. I qu

Re: why cannot assign to function call

2009-01-11 Thread Mark Wooding
ru...@yahoo.com wrote: > But if you'll note, I said "if ..." referring to a couple of > hypothetical C-like languages, so your chapter-and-verse quote from > the standard, while interesting and appreciated, was basically > irrelevant. Ah, what you actually said was still quoted above (thanks):

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-11 Thread Mark Wooding
Carl Banks wrote: [Dynamically adding and removing instance attributes...] > Here's a couple examples of where it's useful: > > 1. Sometimes classes are initialized without calling __init__, [...] > 2. Some classes have factory classmethods [...] > 3. Some objects, such as proxies, have uncerta

Re: why cannot assign to function call

2009-01-13 Thread Mark Wooding
Steven D'Aprano wrote: > I found it interesting. Well, that's something, at any rate. > I think this conversation is reaching it's natural end. Frustration > levels are rising. I think you may be right. That said... > So I'm going to take a different tack in an attempt to reduce > frustrat

Re: why cannot assign to function call

2009-01-14 Thread Mark Wooding
Steven D'Aprano wrote: > > Ah! (say I) but assignment in C and Pascal looks different from the way > > it looks in C > > I'm sorry, that confuses me. Assignment in C looks different from the way > it looks in C? I guess the second C should be Python. Yes, you're right. Stupid mistake on my par

Re: why cannot assign to function call

2009-01-14 Thread Mark Wooding
Aaron Brady wrote: > On Jan 13, 5:06 pm, Mark Wooding wrote: > snip > > I'm going to move away from the formal semantics stuff and try a > > different tack. Here's what I think is the defining property of > > pass-by-value (distilled from the formal approach

Re: List comprehension - NameError: name '_[1]' is not defined ?

2009-01-15 Thread Mark Wooding
mario ruggier writes: > Some info on its security is at: > http://evoque.gizmojo.org/usage/restricted/ > Tell you what, if you find a security hole there (via exposed template > source on a Domain(restricted=True) setup) I'll offer you a nice > dinner (including the beer!) somewhere, maybe at s

Re: List comprehension - NameError: name '_[1]' is not defined ?

2009-01-15 Thread Mark Wooding
mario ruggier writes: > 2009-01-15 22:26:18,704 ERROR [evoque] AttributeError: 'function' > object has no attribute 'func_globals': File "", line 1, in > Damn. So that doesn't work. :-( > But even if inspect did have the func_globals attribute, the "open" > builtin will not be found on __bu

Re: tp_base, ob_type, and tp_bases

2009-01-17 Thread Mark Wooding
Jeff McNeil writes: > Thank you! It was tp_base that was confusing me. The tp_bases member > makes sense as Python supports multiple inheritance. It wasn't > immediately clear that tp_base is there for single inheritance > reasons. It's all quite clear now. > > Is that an optimization of sorts?

Re: Relax Syntax for Augmented Arithmetic?

2009-01-19 Thread Mark Wooding
Steven D'Aprano writes: > There's a practical reason too. You create a new Foo instance, mutate > it with the augmented assignment operator, and then a tenth of a > millisecond later the garbage collector throws it away because it has > a reference count of zero. Only in this specific example.

Re: ifconfig in python

2009-01-19 Thread Mark Wooding
"James Mills" writes: > On Tue, Jan 20, 2009 at 10:28 AM, Nehemiah Dacres > wrote: >> Is ther an easy way to get the resolved ip address of the machine a >> script is running on? socket.gethostbyname(socket.gethostname) has >> only returned the ip address of my loop back interface ... not very

Re: ifconfig in python

2009-01-20 Thread Mark Wooding
Дамјан Георгиевски writes: > Something *like* this could work: > > myip = urllib2.urlopen('http://whatismyip.org/').read() This is going to cause all manner of problems. Firstly, many users are stuck behind NAT routers. In this case, the external service will report the address of the r

Re: Doubts related to subprocess.Popen()

2009-01-20 Thread Mark Wooding
srinivasan srinivas writes: > Does subprocess.Popen() count a new open file for each suprocess? I > mean does it occupy an entry in file descriptor table of parent > process? If so, wat is each file descriptor connected to? On Unix, subprocess.Popen will use up a file descriptor in the parent f

Re: Doubts related to subprocess.Popen()

2009-01-20 Thread Mark Wooding
"Diez B. Roggisch" writes: > Usually, each new process has three file-descriptors associated with > it - stdin,stdout and stderr. > > So when you span a process, the overall count of FDs should increase > by three. Yes, but that's irrelevant. There are two file limits which are relevant: * t

Re: ifconfig in python

2009-01-20 Thread Mark Wooding
"rasikasriniva...@gmail.com" writes: > one way to get your head around this is - IP Addresses are associated > with the interface and not the computer. distinction may be subtle but > critical. Actually this is wrong for most Unix systems, which use the `weak end-system model' described in RFC11

Re: ifconfig in python

2009-01-20 Thread Mark Wooding
"bruce" writes: [a top-posted monstrosity] > so the question really starts to look like: > > -what's the default listening address for my app (insert nic)? > -what's the default sending address for my app (insert nic)? > -what's the default listening address for my server? > -what's the defa

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-20 Thread Mark Wooding
"Russ P." writes: > Actually, in addition to the enforcement of "private," you also need > the enforcement of "protected." Oh, heavens. If you want C++ or any of its progeny, you know where to find them. Besides, those languages have a horrific design mistake because they conflate the class sy

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-20 Thread Mark Wooding
Steven D'Aprano writes: > The consequence of this dynamism is that the Python VM can't do many > optimizations at all, because *at any time* somebody might mess with the > implementation. But 90% of the time nobody does, so Python is needlessly > slow 90% of the time. Wouldn't it be nice if th

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-20 Thread Mark Wooding
"Russ P." writes: > Rather than waste more time replying to your post, Let me just refer > you to an excellent post that you may have missed earlier in this > thread by Mr. D'Aprano: I've responded to that now. (Steven and I can't even agree on a description for simple parts of Python semantics

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-21 Thread Mark Wooding
"Russ P." writes: > Which is why I was hoping that Python might get enforced data hiding > as well as optional static type declarations that can actually be used > for static verification. But maybe that's all just a pipe dream on my > part -- or "onanism." I think that, if you want static assur

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-21 Thread Mark Wooding
"Russ P." writes: > I'm not sure what you mean by "conflating module and class systems." > Are you referring to the fact that Java requires each class to be in > its own file of the same name (I don't use Java, but that's what I've > heard)? If so, I agree that is a bad idea. No. I mean that us

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-21 Thread Mark Wooding
Scott David Daniels writes: > Nowhere in this discussion is a point that I find telling: Python's > policy of accessibility to the full data structure allows simple > implementation of debugging software, rather than the black arcana > that is the normal fare of trying to weld debuggers into the

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-21 Thread Mark Wooding
Luis Zarrabeitia writes: > Btw, the correctness of a program (on a turing-complete language) > cannot be statically proven. Ask Turing about it. Be careful! Given a putative correctness-checking algorithm, there exist programs for which the algorithm gives the wrong answer. That doesn't necess

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-22 Thread Mark Wooding
Paul Rubin writes: > Also, the application area matters. There is a difference between > programming for one's own enjoyment or to do a personal task, and > writing programs whose reliability or lack of it can affect other > people's lives. I've never done any safe

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-22 Thread Mark Wooding
Steven D'Aprano writes: > On Thu, 22 Jan 2009 15:12:31 +0100, Bruno Desthuilliers wrote: >> Steven D'Aprano a écrit : >>> But if you have free access to attributes, then *everything* is >>> interface. >> >> Nope. > > How could anyone fail to be convinced by an argument that detailed and > carefu

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-22 Thread Mark Wooding
Bruno Desthuilliers writes: > Paul Rubin a écrit : >> I'd say that Python's FP characteristics are an important part of its >> expressiveness. > > Indeed - but they do not make Python a functional language[1]. Python is > based on objects, not on functions, I'd have a good go at defining a func

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-23 Thread Mark Wooding
Steven D'Aprano writes: > On Thu, 22 Jan 2009 19:10:05 +0000, Mark Wooding wrote: >> Well, your claim /was/ just wrong. But if you want to play dumb: the >> interface is what's documented as being the interface. > > But you miss my point. Evidently. > We&#

Re: Relax Syntax for Augmented Arithmetic?

2009-01-23 Thread Mark Wooding
a...@pythoncraft.com (Aahz) writes: > Actually, that is not correct. You're right, evidently. [snip] a > (1, ['foo', 'bar'], 'xyzzy') a[1] += ['spam'] > Traceback (most recent call last): > File "", line 1, in ? > TypeError: object doesn't support item assignment a > (1, ['foo

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-23 Thread Mark Wooding
"Russ P." writes: > OK, fine, you can change the code of another member of the team. Are > you going to check with him first, or just do it? The point is that > changing an interface requires agreement of the team members who use > that interface, whether on the calling or the implementation side

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-23 Thread Mark Wooding
Steven D'Aprano writes: > You've built something full of user serviceable parts. You've > insisted, publicly and loudly, that the ability to modify those parts > is absolutely essential, you've rejected every effort to lock down > those internals, and then when somebody does exactly what you > en

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-23 Thread Mark Wooding
"Russ P." writes: > Was this library module released in source form? > > If so, then why would you care that it has enforced access > restrictions? You can just take them out, then do whatever you would > have done had they not been there to start with. I don't see how that > is any more work tha

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-23 Thread Mark Wooding
Steve Holden writes: > Annotations *have* made it into 3.0, so it's possible that the might > become usable. Remember, they'll always be optional, so those who don't > want to use them won't lose anything at all. There's a problem here. An interface has two sides. Access control annotations, a

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-23 Thread Mark Wooding
Steven D'Aprano writes: > On Fri, 23 Jan 2009 13:57:52 +0100, Bruno Desthuilliers wrote: >> Why on earth couldn't I change the code of another member of my team if >> that code needs changes ? The code is the whole team's ownership. > > That's a model that works well when you have a small team of

Re: Dynamic methods and lambda functions

2009-01-23 Thread Mark Wooding
unine...@gmail.com writes: > class Person: > def __init__(self): > for prop in props: > setattr(self, "__" + prop[0], prop[1]) > setattr(Person, "Get" + prop[0], lambda self: getattr > (self, "__" + prop[0])) [...] > The attributes are right, but the getter ar

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-23 Thread Mark Wooding
Steven D'Aprano writes: > I did? Where did I make that assumption? I inferred it from the juxtaposition, apparently in error. Sorry. > What I said was that the model "The code is the whole team's ownership" > doesn't work well for large projects. *One* reason it doesn't work for > large proj

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-23 Thread Mark Wooding
array and cause buffer overflows, and random Python > code could cause core dumps (and possibly even security exploits). [...] > As I see it, you have two coherent positions. On the one hand, you could > be like Mark Wooding, and say that Yes you want to risk buffer overflows > by

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-25 Thread Mark Wooding
"Russ P." writes: > Calling a one-word change a "fork" is quite a stretch, I'd say. I wouldn't. I've forked a project P if I've made a different version of it which isn't going to be reflected upstream. Now I've got to maintain my fork, merging in changes from upstream as they happen, and upgr

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-25 Thread Mark Wooding
"Russ P." writes: > Imagine a person who repairs computers. He is really annoyed that he > constantly has to remove the cover to get at the guts of the computer. > So he insists that computers cases should be made without covers. Poor analogy. He gets fed up that the computers he's meant to be

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-25 Thread Mark Wooding
Steven D'Aprano writes: > On Fri, 23 Jan 2009 21:36:59 -0500, Luis Zarrabeitia wrote: >> It makes sense... if the original author is an egotist who believes he >> must control how I use that library. > > Then I guess Guido must be such an egotist, because there's plenty of > internals in Python

Re: Doc for extended call syntax; was: Re: unzip array of arrays?

2009-01-25 Thread Mark Wooding
Steve Holden writes: > No, you aren't mistaken. Looking at the "*" symbol in the 2.6 > documentation index it lists only two references. The first is the > language manual's explanation of its use in the def statement, the > second is a transitory reference to its use in function calls, but > tha

Re: Pythonic list/tuple/dict layout?

2009-01-25 Thread Mark Wooding
Akira Kitada writes: > I collected common layout from existing code and pasted them below. > My vote would go to d1. How about yours? It seems that I use both d1 and d4, though in both cases I omit the trailing commas. I use d1 when each item is on a separate line, and d4 when I'm packing them

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-25 Thread Mark Wooding
"Russ P." writes: > On Jan 25, 10:04 am, Mark Wooding wrote: > > But what if you type "mumble._seekrit" in several places, then the > library implementer decides to give in to your nagging and makes it > "public" by changing it to "mumble.see

Re: Cartesian Product of two lists (itertools)

2009-01-25 Thread Mark Wooding
Thorsten Kampe writes: > [((1, 4), 7), ((1, 4), 8), ((1, 5), 7), ((1, 5), 8), ((2, 4), 7), ((2, > 4), 8), ((2, 5), 7), ((2, 5), 8)] [...] > What's the best way to pre-process the arguments to "itertools.product" > or to post-process the result of "itertools.product" to get what I > want?! P

Re: Counting number of objects

2009-01-25 Thread Mark Wooding
Andreas Waldenburger writes: > On Sun, 25 Jan 2009 09:23:35 -0800 (PST) Kottiyath > wrote: > >> class a(object): >> counter = 0 >> def __new__(cls, *args, **kwargs): >> a.counter += 1 >> return object.__new__(cls, *args, **kwargs) Hmm. Exceptions raised during object cr

Re: ob_type in shared memory

2009-01-25 Thread Mark Wooding
Aaron Brady writes: > I am writing an extension using shared memory. I need a data type > that is able to reassign its 'ob_type' field depending on what process > is calling it. That sounds scary! > Object 'A' is of type 'Ta'. When process 'P' is looking at it, it > needs to have an 'ob_type'

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-25 Thread Mark Wooding
"Russ P." writes: [snip stuff I don't disagree with] > That makes renaming and refactoring riskier in general in Python than > in statically typed languages with enforced access restrictions. More > care and attention to detail is needed to do it right in Python. In fact, I don't disagree with

Re: Dynamic methods and lambda functions

2009-01-26 Thread Mark Wooding
Michael Torrie writes: > Basically, don't use a lambda. Create a real, local closure with a > nested def block. That way the closure is created every time the > parent function is called. Nope. I explained the real problem quite clearly, and it's to do with the difference between binding and

Re: Dynamic methods and lambda functions

2009-01-26 Thread Mark Wooding
Steve Holden writes: > Mark Wooding wrote: >> * Assignment stores a new (reference to a) value in the variable. >> >> * Binding modifies the mapping between names and variables. >> > I realise I have omitted what was doubtless intended to be explanatory >

Re: Doc for extended call syntax; was: Re: unzip array of arrays?

2009-01-27 Thread Mark Wooding
Bryan Olson writes: > Mark Wooding wrote: >> There's a full description of it in 5.4.3 in the Language Reference, but >> apparently not indexed. > > So I guess this means I can duck out of writing up a lecture on my own > understanding of Python's extended call

Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Address already in use')

2009-01-27 Thread Mark Wooding
Laszlo Nagy writes: > I have a program that uses socket.bind() and socket.listen() > frequently. After that program stops, it is not able to bind() again for a > while: This is the usual TIME-WAIT problem. The TCP protocol requires one end of the connection (whichever actually started the close

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-27 Thread Mark Wooding
[No, my email address doesn't begin `m...@'. Fixed.] Michele Simionato writes: > On Jan 21, 2:11 am, Mark Wooding wrote: > >> CLOS is much more complex and dynamic than Python's object system; >> but it can be compiled very aggressively. > > I agree

Re: How many followers of comp.lang.python

2009-01-27 Thread Mark Wooding
Grant Edwards writes: > I've always found comp.lang.c to be a rather dangerous place as well. Hey, I grew up in comp.lang.c! I'd have to agree with you, though. (I try to play nice when I'm here.) In fact, comp.lang.* generally has a reputation as a place you don't want to find yourself afte

Re: Pexpect and telnet not communicating properly

2009-01-27 Thread Mark Wooding
David Anderson writes: > I am trying to automate the following session - to talk to my router: > > telnet speedtouch [...] > I am using the following code: [...] > child.expect('sername : ') > child.sendline('Administrator') I've scripted communications with my Speedtouch 510 using pexpect: I us

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-27 Thread Mark Wooding
"Russ P." writes: > If Python had a "private" keyword (or equivalent), for example, the > user would only need to delete it wherever necessary to gain the > desired access. And you obviously weren't listening when we said that having to make source code changes to upstream modules was a serious

Re: How to get atexit hooks to run in the presence of execv?

2009-01-29 Thread Mark Wooding
ro...@panix.com (R. Bernstein) writes: > Recently, I added remote debugging via TCP sockets. (Well, also FIFO's > as well but closing sockets before restarting is what's of concern.) > > I noticed that execv in Python 2.5.2 doesn't arrange exit hooks to get > called. Should it? I'd consider that

Re: Number of bits/sizeof int

2009-02-02 Thread Mark Wooding
Jon Clements writes: > "The int() type gained a bit_length method that returns the number of > bits necessary to represent its argument in binary:" > > Any tips on how to get this in 2.5.2 as that's the production version > I'm stuck with. def nbits(x): ## Special cases. if x == 0: return 0

Re: Number of bits/sizeof int

2009-02-02 Thread Mark Wooding
John Machin writes: > 3 can be represented in 2 bits and at the same time -3 can be > represented in 2 bits?? But 2 bits can support only 2 ** 2 == 4 > different possibilities, and -3 .. 3 is 7 different integers. Yeah, I made some arbitrary choices about what to do with non-positive inputs. If

Re: is python Object oriented??

2009-02-02 Thread Mark Wooding
"Russ P." writes: > I am not sure why people keep "mentioning" that "Python is not Java." > As a slogan, it is rather misleading. Python is not C++, Ada, or Scala > either. All of those languages have enforced access restriction. Why > only mention Java? Because Java is a well-known member of a

Re: Date Comparison

2009-02-03 Thread Mark Wooding
mohana2...@gmail.com writes: > I need to compare two dates and find the number of days between those > two dates.This can be done with datetime module in python as below, > but this is not supported in Jython. > > example > from datetime import date > a=datetime.date(2009,2,1) > b=datetime.date(2

Re: is python Object oriented??

2009-02-04 Thread Mark Wooding
"Russ P." writes: > Imagine you own a company, and you decide to lease an office building. > Would you expect the office doors to have locks on them? Oh, you > would? Why? You mean you don't "trust" your co-workers? What are locks > but enforced access restriction? Huh? The lock on the door isn

Re: is python Object oriented??

2009-02-04 Thread Mark Wooding
Steven D'Aprano writes: > Now, that's a toy example. Languages like Ada make correctness proofs, > well, perhaps not easy, but merely difficult compared to impossible for > languages like Python. Say `generally impractical' rather than `impossible' and I'll agree with you. But I'm not actuall

Re: Where & how to deallocate resources in Python C extension

2009-02-04 Thread Mark Wooding
fredbasset1...@gmail.com writes: > I've written a C extension, see code below, to provide a Python > interface to a hardware watchdog timer. As part of the initialization > it makes some calls to mmap, I am wondering should I be making > balanced calls to munmap in some kind of de-init function?

Re: structs

2009-02-04 Thread Mark Wooding
Keith Thompson writes: > "Gary Herron" writes: >> Python *is* object-oriented > > I disagree. Care to provide proof of that statement? AWOOGA! The article I'm following up to (together with at least one other) is a forgery, and the Followup-To header is set to comp.lang.c as part of an effort

Re: Using while loop and if statement to tell if a binary has an odd or even number of 1's.

2009-02-06 Thread Mark Wooding
Duncan Booth writes: > Mark Dickinson wrote: [snip] >> while n: >> count += 1 >> n &= n-1 >> return count >> >> is_even = count_set_bits(the_int) % 2 == 0 >> >> ...but anyone submitting this as a homework >> solution had better be prepared to explain why >> it works. >>

Re: greenlets and how they can be used

2009-01-03 Thread Mark Wooding
James Mills wrote: > The "greenlet" from http://codespeak.net/py/dist/greenlet.html > is a rather interesting way of handling flow of control. Ahh, yes. It's actually a rather old idea, but too rarely used. > What can "greenlet"'s be used for ? What use-cases have you guys used > them for (if

Re: Rich Comparisons Gotcha

2009-01-05 Thread Mark Wooding
Steven D'Aprano wrote: > There is nothing to blame them for. This is the correct behaviour. NaNs > should *not* compare equal to themselves, that's mathematically > incoherent. Indeed. The problem is a paucity of equality predicates. This is hardly surprising: Common Lisp has four general-pu

Re: Rich Comparisons Gotcha

2009-01-05 Thread Mark Wooding
Steven D'Aprano wrote: > I've already mentioned NaNs. Sentinel values also sometimes need to > compare not equal with themselves. Forcing them to compare equal will > cause breakage. There's a conflict between such domain-specific considerations (NaNs, strange sentinels, SAGE's equations), and r

Re: Rich Comparisons Gotcha

2009-01-06 Thread Mark Wooding
Steven D'Aprano wrote: > Such assumptions only hold under particular domains though. You can't > assume equality is an equivalence relation once you start thinking > about arbitrary domains. >From a formal mathematical point of view, equality /is/ an equivalence relation. If you have a relation

Re: why cannot assign to function call

2009-01-06 Thread Mark Wooding
Steven D'Aprano wrote: > By all means, if Derek doesn't like the assignment model used by Python > (and Java, Ruby, C#, Perl, RealBasic, VisualBasic, Lua, and many other > languages going back to at least CLU in the mid 1970s) It goes back to Lisp in the late 1950s. [snip stuff I agree with.

Re: why cannot assign to function call

2009-01-06 Thread Mark Wooding
Steven D'Aprano wrote: > (3) Those who come from an entirely different programming model, say, > Forth or Haskell. For them, Python's assignment model is going to be the > least of their worries. Actually, Haskell's assignment model (you have to grubbing about for IORefs or STRefs to find it b

Re: why cannot assign to function call

2009-01-06 Thread Mark Wooding
Steven D'Aprano wrote: > I don't think so. Variables in algebra are quite different from variables > in programming languages. Contrast the statement: > > x = x+1 > > as a programming expression and an algebraic equation. As a programming > expression, it means "increment x by one". But as an

Re: why cannot assign to function call

2009-01-06 Thread Mark Wooding
Derek Martin wrote: > I think I have though, not that it matters, since that was never > really my point. Python's assignment model requires more explanation > than the traditional one, simply to state what it does. That alone is > evidence (but not proof). Hmm. Actually, it's not the assignm

Re: Rich Comparisons Gotcha

2009-01-06 Thread Mark Wooding
Steven D'Aprano wrote: > To prove my claim, all you need is two domains with a mutually > incompatible definition of equality. That's not so difficult, surely? How > about equality of integers, versus equality of integers modulo some N? No, that's not an example. The integers modulo N form a

Re: why cannot assign to function call

2009-01-06 Thread Mark Wooding
Steven D'Aprano wrote: > If I wanted a reference to a list, I'd expect to *dereference* the > reference to get to the list. That's not what Python forces you do to: > you just use the list as the list object itself. That's odd. No, you give a reference to the list to a function, and the funct

Re: why cannot assign to function call

2009-01-06 Thread Mark Wooding
Steven D'Aprano wrote: > The only tricky thing is that items 1, 2 and 3 can be inside two > different boxes at the same time. There's no obvious real world analogy > to that without the boxes being nested. This ability for objects to be in > two places at once (or even to be inside themselves!

Re: why cannot assign to function call

2009-01-06 Thread Mark Wooding
ru...@yahoo.com wrote: > Is not the proper term "aliasing"? Perhaps Python "variables" should > be called "alises". No. The proper term is most definitely `binding': see SICP, for example. (Wikipedia has a link to the full text.) The topic of `aliasing' deals with a problem in compiler imple

Re: why cannot assign to function call

2009-01-07 Thread Mark Wooding
Steven D'Aprano wrote: > Only in the sense that the behaviour of *real world* objects don't > entirely match the behaviour of Python objects. If you just accept > that Python objects can be in two places at once, an unintuitive > concept I accept but hardly difficult to grasp, then you don't need

Re: Rich Comparisons Gotcha

2009-01-07 Thread Mark Wooding
Steven D'Aprano wrote: > It's only incoherent if you need equality to be an equivalence relation. > If you don't, it is perfectly reasonable to declare that i"abc" equals > "abc". Right! And if you didn't want an equivalence relation, then `==' will suit you fine. The problem is that some ap

Re: why cannot assign to function call

2009-01-08 Thread Mark Wooding
ru...@yahoo.com wrote: > I thought you were objecting to Python's use of the term "binding" > when you wrote: [snip] > in response to someone talking about "...all those who use the term > \"name binding\" instead of variable assignment...". Oh, that. Well, the terms are `binding' and `assign

Re: why cannot assign to function call

2009-01-08 Thread Mark Wooding
[Steven's message hasn't reached my server, so I'll reply to it here. Sorry if this is confusing.] Aaron Brady wrote: > On Jan 8, 1:45 am, Steven D'Aprano > wrote: > > On Wed, 07 Jan 2009 10:17:55 +, Mark Wooding wrote: > > > > > The `they&

Re: why cannot assign to function call

2009-01-08 Thread Mark Wooding
Erik Max Francis wrote: > Terry Reedy wrote: > > > >>> a='par'+'rot' > > >>> b='parrot' > > >>> a is b > > True > > One exactly doesn't really say much. It's implementation dependent, and > depends on the length of the string: > > >>> a = 'this is a much longer ' + 'parrot' > >>> b = 'thi

Re: why cannot assign to function call

2009-01-09 Thread Mark Wooding
ru...@yahoo.com wrote: > As a side comment (because it always bugs me when I read this, even > though I read it in very authoritative sources), ISTM that C passes > everything by value except arrays; they are passed by reference (by > passing a pointer to the array by value.) Admittedly, the clo

Re: why cannot assign to function call

2009-01-09 Thread Mark Wooding
[Sigh. I must apologize for the length of this article. I can't, alas, see a satisfactory way of trimming it. The doubly-quoted stuff later on was by me.] Steven D'Aprano wrote: > I'm pretty sure that no other pure-Python coder has manipulated > references either. They've manipulated objects

Re: why cannot assign to function call

2009-01-09 Thread Mark Wooding
Aaron Brady wrote: > Possible compromise. You can think of functions as mutation-only. > You pass the object, and it gets a new (additional) name. The old > name doesn't go in. Huh? That doesn't explain circular data structures at all, unless your idea of `name' is unrelated to the identifi

Re: why cannot assign to function call

2009-01-09 Thread Mark Wooding
Steven D'Aprano wrote: > Python doesn't do the same thing as C. It actually passes the same value > to the function, without copying it. > > Why oh why do you keep insisting that Python is no different from C? I'm beginning to think that you're not bothing to read what I'm writing, but I'll as

Re: why cannot assign to function call

2009-01-09 Thread Mark Wooding
ru...@yahoo.com wrote: > If one accepts that there are a "lot" of people who post in here that > clearly are surprised by Python's assignment semantics, But one should not accept that. One might accept that there are many who post who claim that they are surprised by Python's assignment semant

Re: Avoiding local variable declarations?

2008-11-14 Thread Mark Wooding
Chris Mellon <[EMAIL PROTECTED]> wrote: > Any time you port between languages, it's rarely a good idea to just > convert code verbatim. For example: > > import random, string > def random_char(): > return random.choice(string.ascii_letters + string.digits) Note that this code doesn't preserve

Re: Clustering the keys of a dict according to its values

2008-11-14 Thread Mark Wooding
Florian Brucker <[EMAIL PROTECTED]> wrote: > That is, generate a new dict which holds for each value of the old > dict a list of the keys of the old dict that have that very value. > Another requirement is that it should also work on lists, in that case > with indices instead of keys. We may assum

Re: Avoiding local variable declarations?

2008-11-19 Thread Mark Wooding
greg <[EMAIL PROTECTED]> wrote: > I've only ever seen "identity element" in English mathematics. > "Neutral element" sounds like something my car's gearbox > might have... I've encountered both. I think `neutral element' is more common when dealing with the possibility that it might not be uniqu

Re: why cannot assign to function call

2009-02-28 Thread Mark Wooding
Ethan Furman writes: > Mark Wooding wrote: >> Here's what I think is the defining property of pass-by-value [...]: >> >> The callee's parameters are /new variables/, initialized /as if by >> assignment/ from the values of caller's argument expressio

  1   2   3   >