Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'static': 0.03; 'compiler': 0.05; 'needed,': 0.05; '(using': 0.07; 'alignment': 0.07; 'assignment': 0.07; 'caller': 0.07; 'convention,': 0.09; 'immutable': 0.09; 'integer,': 0.09; 'integers': 0.09; 'mutable': 0.09; 'win64': 0.09; 'python': 0.11; 'stack': 0.13; 'thursday,': 0.13; '(but': 0.15; 'argument': 0.15; 'value.': 0.15; '(eg.': 0.16; 'descriptors,': 0.16; 'distinction': 0.16; 'expecting': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'function.)': 0.16; 'lisp': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'modified.': 0.16; 'passed.': 0.16; 'received:192.168.1.4': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'sees': 0.16; 'still,': 0.16; 'variations': 0.16; 'zero,': 0.16; 'wrote:': 0.16; 'looked': 0.16; 'memory': 0.17; 'element': 0.18; 'integer': 0.18; 'wednesday': 0.18; 'language': 0.19; 'machine': 0.21; '(or': 0.21; "aren't": 0.22; 'fine,': 0.22; 'function,': 0.22; 'logical': 0.22; 'parameter': 0.22; 'pass': 0.22; 'code.': 0.23; 'bit': 0.23; '2015': 0.23; 'passing': 0.23; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'equivalent': 0.27; "doesn't": 0.28; "i'm": 0.29; '32-bit': 0.29; 'barbara': 0.29; 'does,': 0.29; 'python).': 0.29; 'reduced': 0.29; 'weak': 0.29; 'function': 0.30; 'values': 0.30; 'convention': 0.31; 'subject:time': 0.31; 'trouble': 0.31; "can't": 0.32; 'included': 0.32; 'implement': 0.32; 'addresses': 0.32; 'received:84': 0.32; "d'aprano": 0.33; 'shift': 0.33; 'steven': 0.33; 'another': 0.34; 'everyone': 0.34; 'that,': 0.34; 'changed': 0.35; 'could': 0.35; 'to:addr:python- list': 0.35; 'functions.': 0.35; 'i.e.': 0.35; 'really': 0.35; 'but': 0.36; 'being': 0.36; 'too': 0.36; '(and': 0.36; 'two': 0.37; 'subject:: ': 0.37; 'level': 0.37; 'version': 0.38; 'community': 0.38; 'goes': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'area': 0.39; 'received:192': 0.39; 'some': 0.40; 'easy': 0.60; 'your': 0.60; 'back': 0.61; 'even': 0.61; 'more.': 0.62; 'making': 0.64; 'sharing': 0.64; 'between': 0.65; 'user,': 0.67; 'foreign': 0.69; 'million': 0.73; 'address,': 0.77; '100': 0.79; '1970s,': 0.84; 'x64': 0.84; 'technically': 0.91 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=dZcO3Bne c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=QrohdLjRRo4A:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=R4Y_H_aUsiTFJwcqepkA:9 a=j3IjEnnwpLOyJky7:21 a=dnImvJOghOxAVmo7:21 a=QEXdDO2ut3YA:10 X-AUTH: mrabarnett@:2500 Date: Thu, 21 May 2015 17:50:32 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Slices time complexity References: <9ceklad15llnv3npejq9iuh91soci8aeqo@4ax.com> <7ea01590-a559-46e5-abf5-29622e39aae7@googlegroups.com> <555ac697$0$12910$c3e8da3$5496439d@news.astraweb.com> <862693ca-42cf-4f5b-ac12-133e43e7606b@googlegroups.com> <878uclf3bt.fsf@elektro.pacujo.net> <555af171$0$12995$c3e8da3$5496439d@news.astraweb.com> <874mn9ezaw.fsf@elektro.pacujo.net> <555b2fa9$0$12996$c3e8da3$5496439d@news.astraweb.com> <87oalfooz7.fsf@elektro.pacujo.net> <92992653-d511-4e33-a21d-541eeda4799b@googlegroups.com> <555c225b$0$2769$c3e8da3$76491128@news.astraweb.com> <555d6ad8$0$2763$c3e8da3$76491128@news.astraweb.com> <755415ac-25c8-40db-b3c2-78111ed25621@googlegroups.com> In-Reply-To: <755415ac-25c8-40db-b3c2-78111ed25621@googlegroups.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 56 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1432227041 news.xs4all.nl 2922 [2001:888:2000:d::a6]:51577 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:91016 On 2015-05-21 14:34, bartc wrote: > On Thursday, 21 May 2015 06:19:39 UTC+1, Steven D'Aprano wrote: >> On Wednesday 20 May 2015 19:56, Bartc wrote: > >> What you *shouldn't* do is implement your own argument convention, > > (That's exactly what I did for my static language compiler which > generates x64 code. The Win64 calling convention was far too > complicated, and required 16-byte stack alignment which was another > headache. My private calling convention works fine! But I have to use > the official one for calling foreign (eg. C) functions. > > This is at a lower level than the logical or language view of > parameter passing, but still, you don't always have to do what > everyone else does.) > >> Don't do what the Lua community does, which is invent a stupid >> distinction between "reference types" and "value types" so they too >> can misuse terminology: > > But in the mind of the user, such a distinction can be intuitive. If > I'm passing a 32-bit integer, it is easy to think of the value being > passed. With a 100 million element array, it harder to think of it > being passed by value than by reference. > >> This calling convention has been known as pass by sharing (or >> variations of that, like "pass by object sharing") since it was >> named by Barbara Liskov in the 1970s, for the language CLU, but the >> convention itself goes back to Lisp in the 1950s. > > I looked it up expecting a new convention to solve all my problems. > But it's just a re-statement of how Python works anyway! > > So a mutable object passed to a function can be changed by that > function, so that the caller sees the change. An immutable object > can't be changed in the same way, but only because Python doesn't > allow it to be modified. (But it does allow assignment to the version > in the function.) > > Using what is really pass-by-reference for everything is fine, but > I'm having some trouble with making it efficient for small integer > values (I think this is a weak area of Python). Even with my clunky > system of passing descriptors, the equivalent of BINARY_ADD for two > small integers can be reduced to perhaps 10 or 12 machine > instructions, byte-code dispatch *and* double type-dispatch overheads > included (using ASM that is; and technically the type-dispatching is > by-passed). > > If small integers need to be heap-allocated and managed, then it > might need a few more. (And then Python will auto-range these to > arbitrary precision as needed, another difference.) > If memory addresses aren't byte-aligned, you could use the least- significant bit to indicate whether it's a small integer, i.e. if it's zero, then it's an address, else shift right by 1 bit arithmetically for the integer value.