Re: What other languages use the same data model as Python?
In article mailman.1286.1304760534.9059.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: On Sat, May 7, 2011 at 7:21 PM, Gregory Ewing greg.ew...@canterbury.ac.nz wrote: Hans Georg Schaathun wrote: You cannot reference nor manipulate a reference in python, and that IMHO makes them more abstract. You can manipulate them just fine by moving them from one place to another: I think manipulate here means things like pointer arithmetic, which are perfectly normal and common in C and assembly, but not in languages where they're references. Adding an integer to a reference to an array element could have been perfectly well-defined in Algol: ref real operator+(ref real, int) That is called overloading of the plus operator not pointer arithmetic. It is a misconception that these manipulation are dirty or ill-defined or unsafe. A similar extension would be possible in Python. Allusion to assembler where one adds a number to a register and can't tell whether the register contains an address or data are misleading. [This is not to say that I think it is advisable]. Chris Angelico Groetjes Albert. -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
In article 4dc7fa2f$0$29991$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Mon, 09 May 2011 12:52:27 +1200, Gregory Ewing wrote: Steven D'Aprano wrote: Since you haven't explained what you think is happening, I can only guess. Let me save you from guessing. I'm thinking of a piece of paper with a little box on it and the name 'a' written beside it. There is an arrow from that box to a bigger box. +-+ +---+ | | a | --+| | +---+ | | +-+ There is another little box labelled 'b'. After executing 'a = b', both little boxes have arrows pointing to the same big box. [...] In this model, a reference is an arrow. Manipulating references consists of rubbing out the arrows and redrawing them differently. All very good, but that's not what takes place at the level of Python code. It's all implementation. I think Hans Georg Schaathun made a good objection to the idea that Python has references: In Pascal a pointer is a distinct data type, and you can have variables of a given type or of type pointer to that given type. That makes the pointer a concrete concept defined by the language. The same can't be said of references in Python. It's not part of Python the language, although it might be part of Python's implementation. Also in this model, a variable is a little box. It's *not* the same thing as a name; a name is a label for a variable, not the variable itself. That's essentially the same model used when dealing with pointers. I've used it myself, programming in Pascal. The little box named a or b is the pointer variable, and the big box is the data that the pointer points to. It's not an awful model for Python: a name binding a = obj is equivalent to sticking a reference (a pointer?) in box a that points to obj. Certainly there are advantages to it. But one problem is, the model is ambiguous with b = a. You've drawn little boxes a and b both pointing to the big box (which I deleted for brevity). But surely, if a = 1234 creates a reference from a to the big box 1234, then b = a should create a reference from b to the box a? There are cleaner languages. Algol 68 , Forth. This is Forth. VARIABLE A VARIABLE B 1234 ( anonymous object created by the language ) A ! A @ B !( Copy the content, equivalent of B=A). Algol 68 B:=A compiler : THINK ! THINK ! A is a ref int so it can't be stored into b which is a ref int which is the name of a place where an int can be stored (not where a ref int could be stored.) Solution: Algol dereferences A into an int, by getting its content. But it is a rule, very explicitly explained in the language definition. (If you are that clean you can handle ref ref int q where q is the name of a place where a ref int can be stored.) real a is in fact an abbreviation of ref real a=loc real meaning a is a reference to a local real, that is anonymous. The = means that the connection between a and that real is an identity, i.e. the connection can't be broken. (Forget about C++, casting away const, yuck! ) In Forth and in Algol 68 storing a constant into a variable is very different from copying the content of a variable to some other variable. SNIP -- Steven Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
Steven D'Aprano wrote: All very good, but that's not what takes place at the level of Python code. It's all implementation. Actually, you're right. What I've presented is a paper-and-pencil implementation of the Python data model. Together with a set of rules for manipulating the diagram under the direction of Python code, you have a complete implementation of Python that you can execute in your head. And you NEED such an implementation in order to reason correctly about Python programs under all circumstances. I find it very difficult to imagine *any* implementation of Python, computer-based or otherwise, that doesn't have something equivalent to references. Whether you call them that, or pointers, or arrows, or object bindings, or something else, the concept needs to be there in some form. But surely, if a = 1234 creates a reference from a to the big box 1234, then b = a should create a reference from b to the box a? +-+ +---+ | | a | --+| | +---+ | | ^ +-+ | +-|-+ b | | | +---+ You can't expect anyone to draw correct conclusions from the diagram alone; you also need to explain the rules for manipulating the diagram under control of Python code. Here, the explanation goes something like this: 1. The right hand side of an assignment denotes a big box. The literal 1234 in a program denotes a big box containing the integer value 1234. 2. The left hand side of an assignment denotes a little box. The effect of an assignment is to make the arrow from the left hand side's little box point to the big box denoted by the right hand side. So the assignment a = 1234 results in +-+ +---+ | | a | --+| 1234 | +---+ | | +-+ 3. When a name is used on the right hand side, it denotes whichever big box is pointed to by the arrow from its little box. So given the above diagram, the assignment b = a results in +-+ +---+ | | a | --+| 1234 | +---+ | | +-+ ^ +---+| b | --+- +---+ Furthermore, from rule 2 alone it's evident that no assignment can ever make an arrow lead from one little box to another little box. Arrows can only lead from a little box to a big box. That's how it works in C and Pascal (well, at least with the appropriate type declarations). Um, no, it doesn't, really. There's no way 'b = a' can give you that in C; you would have to write 'b = a'. And you couldn't do it at all in standard Pascal, because there is no equivalent to the operator there. Your model is closer to what the CPython implementation actually does, I think it's close -- actually, I would say isomorphic -- to what *any conceivable* Python implementation would do in some form. n = len('hello world') What about outside len? Where's the little box pointing to 'hello world'? So it seems your model fails to deal with sufficiently anonymous objects. Anonymous objects are fine. You just draw a little box and don't write any label beside it. Or you don't bother drawing a little box at all and just draw a big box until such time as some little box that you care about needs to point to it. If that's a problem, then you have the same problem talking about names bound to objects. An anonymous object obviously doesn't have any name bound to it. So you have to admit that objects can exist, at least temporarily, without being bound to anything, or bound to some anonymous thing. Both the call to len and the call to func push their results onto the stack. There's no little box pointing to the result. If you want to model things at that level of detail, then the stack itself is an array of little boxes inside a frame object. And the frame object is pointed to by a little box in its calling frame object, etc. until you get to some global little box, that doesn't have a name in Python, but exists somewhere and keeps the chain of active stack frames alive. But you don't have to draw any of that if you don't want to. For practical reasons, there must be some sort of indirection. But that's implementation and not the VM's model. No, it's not just implementation. Indirection is needed for *correct semantics*, not just practicality. There is a problem with my model of free-floating objects in space: it relies on objects being able to be in two places at once, Yes, that's the point I'm trying to make. While it might be possible to make such a model work,
Re: What other languages use the same data model as Python?
On Tue, May 10, 2011 at 12:29 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: If objects can be in two places at once, why can't names? Just because. Because then you'd need some way to identify which object you wanted to refer to - something like name[0] and name[1]. A tuple is one effective way to do this (sort of - actually, the name points at the tuple and the tuple points at each of the objects). On Tue, May 10, 2011 at 12:47 PM, MRAB pyt...@mrabarnett.plus.com wrote: I had heard something about the meaning of the word gift, so I checked in Google Translate. For Swedish gift it says: noun 1. POISON 2. VENOM 3. TOXIN 4. VIRUS Beware of Swedes bearing gifts! On Tue, May 10, 2011 at 5:41 PM, Gregory Ewing greg.ew...@canterbury.ac.nz wrote: Anonymous objects are fine. You just draw a little box and don't write any label beside it. Or you don't bother drawing a little box at all and just draw a big box until such time as some little box that you care about needs to point to it. If that's a problem, then you have the same problem talking about names bound to objects. An anonymous object obviously doesn't have any name bound to it. So you have to admit that objects can exist, at least temporarily, without being bound to anything, or bound to some anonymous thing. There has to be a way to get from some mythical home location (which we know in Python as locals()+globals()+current expression - the current namespace) to your object. That might involve several names, or none at all, but if there's no such path, the object is unreferenced and must be disposed of. IIRC that's not just an implementation detail (the garbage collector), but a language guarantee (that the __del__ method will be called). Names are immaterial to that. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On 2011-05-10, Gregory Ewing greg.ew...@canterbury.ac.nz wrote: Steven D'Aprano wrote: It's just that the term variable is so useful and so familiar that it's easy to use it even for languages that don't have variables in the C/ Pascal/Fortran/etc sense. Who says it has to have the Pascal/Fortran/etc sense? Because it's easier to communicate if everybody agrees on what a word means. -- Grant Edwards grant.b.edwardsYow! The SAME WAVE keeps at coming in and COLLAPSING gmail.comlike a rayon MUU-MUU ... -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On Tue, 10 May 2011 14:05:34 + (UTC), Grant Edwards invalid@invalid.invalid wrote: : Because it's easier to communicate if everybody agrees on what a word : means. Why should we agree on that particular word? Are there any other words we agree about? Other key words, such as class, object, or function don't have universal meanings. :-) -- :-- Hans Georg -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On 2011-05-10, Hans Georg Schaathun h...@schaathun.net wrote: On Tue, 10 May 2011 14:05:34 + (UTC), Grant Edwards invalid@invalid.invalid wrote: : Because it's easier to communicate if everybody agrees on what a word : means. Why should we agree on that particular word? Are there any other words we agree about? Other key words, such as class, object, or function don't have universal meanings. And what do we mean by agree? What do we mean by mean? It's turtles all they down... -- Grant Edwards grant.b.edwardsYow! at gmail.com -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On Wed, May 11, 2011 at 1:16 AM, Grant Edwards invalid@invalid.invalid wrote: And what do we mean by agree? What do we mean by mean? It's turtles all they down... When I use a word, it means just what I choose it to mean - neither more nor less. -- Humpty Dumpty. Language is for communication. If we're not using the same meanings for words, we will have problems. Chris Angelico PS. By mean, I mean average. Except when I mean mean. But now I'm just being mean. -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On Wed, 11 May 2011 01:27:36 +1000, Chris Angelico ros...@gmail.com wrote: : Language is for communication. If we're not using the same meanings : for words, we will have problems. So if you adopt the word class to mean a type (or composite type), as in python, what word would you use for a class of types (as in haskell or ada)? I think there are too many meanings and too few words ... That's why some languages support overloading. I am afraid we just need to cope with it, overloading I mean. -- :-- Hans Georg -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On Wed, May 11, 2011 at 1:40 AM, Hans Georg Schaathun h...@schaathun.net wrote: On Wed, 11 May 2011 01:27:36 +1000, Chris Angelico ros...@gmail.com wrote: : Language is for communication. If we're not using the same meanings : for words, we will have problems. So if you adopt the word class to mean a type (or composite type), as in python, what word would you use for a class of types (as in haskell or ada)? I think there are too many meanings and too few words ... That's why some languages support overloading. Of course. Nobody ever said that one name had to point to one value... oh wait. Yes, Virginia, there is overloading. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On 5/10/2011 3:41 AM, Gregory Ewing wrote: Actually, you're right. What I've presented is a paper-and-pencil implementation of the Python data model. Together with a set of rules for manipulating the diagram under the direction of Python code, you have a complete implementation of Python that you can execute in your head. I think that it would be both fun and useful to have an animated graphical tutorial that used and box and arrow model. Names should be in ovals (instead of the little boxes used here due to text limitations) to differentiate them from objects. Immutable objects could have solid boundaries and mutables a broken line boundary. Collection objects would have dotted lines to separate slots. Ovals could also use different lines for builtins, globals, and locals. And you NEED such an implementation in order to reason correctly about Python programs under all circumstances. I find it very difficult to imagine *any* implementation of Python, computer-based or otherwise, that doesn't have something equivalent to references. Whether you call them that, or pointers, or arrows, or object bindings, or something else, the concept needs to be there in some form. Since namespaces link names in a namespace with objects not in the namespace, any practical implementation needs a third entity to link or associated each name with an object. This is pretty much needed to explain multiple links without objects being in multiple locations. It is also needed to explain how an object can link to itself. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
Chris Angelico wrote: There has to be a way to get from some mythical home location (which we know in Python as locals()+globals()+current expression - the current namespace) to your object. That might involve several names, or none at all, but if there's no such path, the object is unreferenced and must be disposed of. Yes, that's what I mean by bound to some anonymous thing. Somewhere in the implementation there must be one or more root references, but they don't necessarily have any names that you can refer to from Python. When I say not bound to any name, I just mean that it's okay to leave some bindings out of your diagram if they're not pertinent to what you're trying to illustrate. For example, you can draw a box representing a string object and trust that something will keep it alive long enough for you to draw an arrow to it from the name you're assigning it to. -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On Sat, 07 May 2011 21:21:45 +1200, Gregory Ewing greg.ew...@canterbury.ac.nz wrote: : You can manipulate them just fine by moving them : from one place to another: : : a = b : : You can use them to get at stuff they refer to: : : a = b.c : a[:] = b[:] Surely you can refer to the objects, but you cannot refer to the reference. : You can compare them: : : if a is b: : ... This could be implemented as pointer comparison, but it is not defined as such and there is no requirement that it be. : That's about all you can do with pointers in Pascal, : and I've never heard anyone argue that Pascal pointers : are any more or less abstract than any other piece of : data in that language. In Pascal a pointer is a distinct data type, and you can have variables of a given type or of type pointer to that given type. That makes the pointer a concrete concept defined by the languagedefined by the language. -- :-- Hans Georg -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On Mon, 09 May 2011 12:52:27 +1200, Gregory Ewing greg.ew...@canterbury.ac.nz wrote: : Let me save you from guessing. I'm thinking of a piece of paper with : a little box on it and the name 'a' written beside it. There is an : arrow from that box to a bigger box. : : +-+ :+---+ | | : a | --+| | :+---+ | | : +-+ The flaw of this model, and I am not discounting its merits, just pointing out that it isn't perfect, is that it creates the illusion that references are boxes (objects) just like data objects, leading the reader to think that we could have a reference to a reference. If they are all boxes, by can't we make reference thereto? -- :-- Hans Georg -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On Mon, May 9, 2011 at 8:38 PM, Hans Georg Schaathun h...@schaathun.net wrote: The flaw of this model, and I am not discounting its merits, just pointing out that it isn't perfect, is that it creates the illusion that references are boxes (objects) just like data objects, leading the reader to think that we could have a reference to a reference. If they are all boxes, by can't we make reference thereto? http://www.xkcd.com/895/ Analogies are like diagrams. Not all of them are perfect or useful. The boxes are different sizes. If you really want them to look different, do one as squares and one as circles, but don't try that in plain text. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On Mon, 09 May 2011 12:52:27 +1200, Gregory Ewing wrote: Steven D'Aprano wrote: Since you haven't explained what you think is happening, I can only guess. Let me save you from guessing. I'm thinking of a piece of paper with a little box on it and the name 'a' written beside it. There is an arrow from that box to a bigger box. +-+ +---+ | | a | --+| | +---+ | | +-+ There is another little box labelled 'b'. After executing 'a = b', both little boxes have arrows pointing to the same big box. [...] In this model, a reference is an arrow. Manipulating references consists of rubbing out the arrows and redrawing them differently. All very good, but that's not what takes place at the level of Python code. It's all implementation. I think Hans Georg Schaathun made a good objection to the idea that Python has references: In Pascal a pointer is a distinct data type, and you can have variables of a given type or of type pointer to that given type. That makes the pointer a concrete concept defined by the language. The same can't be said of references in Python. It's not part of Python the language, although it might be part of Python's implementation. Also in this model, a variable is a little box. It's *not* the same thing as a name; a name is a label for a variable, not the variable itself. That's essentially the same model used when dealing with pointers. I've used it myself, programming in Pascal. The little box named a or b is the pointer variable, and the big box is the data that the pointer points to. It's not an awful model for Python: a name binding a = obj is equivalent to sticking a reference (a pointer?) in box a that points to obj. Certainly there are advantages to it. But one problem is, the model is ambiguous with b = a. You've drawn little boxes a and b both pointing to the big box (which I deleted for brevity). But surely, if a = 1234 creates a reference from a to the big box 1234, then b = a should create a reference from b to the box a? +-+ +---+ | | a | --+| | +---+ | | ^ +-+ | +-|-+ b | | | +---+ which is the reference (pointer) model as most people would recognise it. That's how it works in C and Pascal (well, at least with the appropriate type declarations). To get b pointing to the big box, you would need an explicit dereference: b = whatever a points to rather than b = a. Of course, both of these concepts are models, which is another word for lies *wink*. Your model is closer to what the CPython implementation actually does, using actual C pointers, except of course you do need to dereference the pointers appropriately. One of my objections to it is not that it is wrong (all models are wrong) but that it will mislead some people to reason incorrectly about Python's behaviour, e.g. that b now points to the little box a, and therefore if you change what a points to, b will follow along. The whole call by reference thing. I suppose you might argue that you're not responsible for the misunderstandings of blinkered C coders *wink*, and there's something to that. But there's another objection... take, say, the line of Python code: n = len('hello world') I can identify the little box n, which ends up pointing to the big box holding int 11; another little box len, which points to a big box holding a function; and a third big box holding the string 'hello world'. But where is its little box? If len were written in pure Python, then *inside* len's namespace there would be a local little box for the argument. I expect that there is an analogous local little box for built-in functions too. But I don't care what happens inside len. What about outside len? Where's the little box pointing to 'hello world'? So it seems your model fails to deal with sufficiently anonymous objects. I say sufficiently, because of course your model deals fine with objects without names inside, say, lists: the little box there is the list slot rather than a named entry in a namespace. It's not just literals that your model fails to deal with, it's any expression that isn't bound to a little box: n = len('hello world') + func(y) func(y) produces a new object, a big box. Where is the little box pointing to it? If we drop down an abstraction layer, we can see where objects live: code = compile(n = len('hello world') + func(y), '', 'single') import dis dis.dis(code) 1 0 LOAD_NAME0 (len) 3 LOAD_CONST 0 ('hello world') 6 CALL_FUNCTION1 9 LOAD_NAME
Re: What other languages use the same data model as Python?
On 09/05/2011 15:29, Steven D'Aprano wrote: [... snippage galore ...] Slightly abstract comment: while I don't usually get much enjoyment out of the regular Python is call-by-value; no it isn't; yes it is debates, I always enjoy reading Steven D'Aprano's responses. Thanks, Mr D'A. :) TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
Steven D'Aprano wrote: But that's wrong! Names (little boxes) can't point to *slots in a list*, any more than they can point to other names! This doesn't work: -- L = [None, 42, None] -- a = L[0] -- L[0] = 23 -- print(a) # This doesn't work! 23 Minor nitpick -- having a comment saying this doesn't work then having output showing that it does is confusing. I had to load up the interpretor to make sure I was confused! ;) ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
Steven D'Aprano wrote: It's not an awful model for Python: a name binding a = obj is equivalent to sticking a reference (a pointer?) in box a that points to obj. Certainly there are advantages to it. But one problem is, the model is ambiguous with b = a. You've drawn little boxes a and b both pointing to the big box (which I deleted for brevity). But surely, if a = 1234 creates a reference from a to the big box 1234, then b = a should create a reference from b to the box a? :) There's a way around that too. Describe literals as magic names or Platonic names that are bound to objects in ideal space. I actually considered that for a while as a way of explaining to newbs why the characters in a string literal could be different from the characters in the string value. This would probably have troubles of its own; I never took it through the knock-down drag-out disarticulation that would show what the problems were. Mel. -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On 5/9/2011 10:29 AM, Steven D'Aprano wrote: If people then ask, how does the interpreter know the names?, I can add more detail: names are actually strings in a namespace, which is usually nothing more than a dict. Oh, and inside functions, it's a bit more complicated still. And so on. Which is why I think it best to stick with 'A namespace is a many-to-one mapping (in other words, a function) of names to objects'. Any programmer should understand the abstractions 'mapping' and 'function'. Asking how the interpreter finds the object associated with a name amounts to asking how to do tabular lookup. Well, we basically know, though the details depends on the implementation of the table (mapping). An interpreter can *implement* namespaces various ways. One is to objectify names and namespaces as strings and dicts. If the set of names in a namespace is fixed, another way is to objectify names and namespaces as ints and arrays. Python prohibits 'from x import *' within functions precisely to keep the set of local namespace names fixed. Therefore, CPython can and does always use C ints and array for function local namespaces. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On Mon, 9 May 2011 21:18:29 +1000, Chris Angelico ros...@gmail.com wrote: : Analogies are like diagrams. Not all of them are perfect or useful. : : The boxes are different sizes. If you really want them to look : different, do one as squares and one as circles, but don't try that in : plain text. Analogies, even imperfect ones, are good when we are clear about the fact that they are analogies. Using C pointers to illustrate how to use bound names in python may be useful, but only if we are clear about the fact that it is an analogy and do not pretend that it explains it in full. -- :-- Hans Georg -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
Gregory Ewing wrote: +-+ +---+ | | a | --+| | +---+ | | +-+ ^ +---+ | b | --+---| +---+ In this model, a reference is an arrow. Manipulating references consists of rubbing out the arrows and redrawing them differently. Greg, this is an excellent model, thank you for taking the time to put it together for the list... very helpful. Both Summerfield and Lutz use the same model (and almost the identical graphic symbolism) to explain dynamic typing in Python. Summerfield's Programming in Python 3 2nd ed. has a good explanation similar, see pages 17 and 32 (there are others). Lutz has an entire chapter devoted to the topic in Learning Python 4th ed., see chapter six. He calls it the Dynamic Typing Interlude. The model is in-the-field and very workable; and yet, it does have limitations, as most models do. For visual thinkers this model probably comes closest to being most helpful, esp in the beginning. kind regards, m harris -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
Steven D'Aprano wrote: It's just that the term variable is so useful and so familiar that it's easy to use it even for languages that don't have variables in the C/ Pascal/Fortran/etc sense. Who says it has to have the Pascal/Fortran/etc sense? Why should static languages have a monopoly on the use of the term? That seems like a rather languagist attitude! And BTW, applying it to Python is not inconsistent with its usage in Pascal. In the technical vocabulary of Pascal, a variable is anything that can appear on the left hand side of an assignment. The analogous term in C is lvalue. -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
Steven D'Aprano wrote: Or Chinese Gooseberries, better known by the name thought up by a marketing firm, kiwi fruit. And I'm told that there is a language (one of the Nordic ones, IIRC) where kiwi means stone. So in that country they wonder why they should be getting so excited about something called a stonefruit. :-) -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On 10/05/2011 02:51, Gregory Ewing wrote: Steven D'Aprano wrote: Or Chinese Gooseberries, better known by the name thought up by a marketing firm, kiwi fruit. And I'm told that there is a language (one of the Nordic ones, IIRC) where kiwi means stone. So in that country they wonder why they should be getting so excited about something called a stonefruit. :-) I had heard something about the meaning of the word gift, so I checked in Google Translate. For Swedish gift it says: noun 1. POISON 2. VENOM 3. TOXIN 4. VIRUS adjective 1. MARRIED 2. WEDDED -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On Tue, 10 May 2011 13:49:04 +1200, Gregory Ewing wrote: Steven D'Aprano wrote: It's just that the term variable is so useful and so familiar that it's easy to use it even for languages that don't have variables in the C/ Pascal/Fortran/etc sense. Who says it has to have the Pascal/Fortran/etc sense? Why should static languages have a monopoly on the use of the term? That seems like a rather languagist attitude! Established usage. They came first, and outnumber us :/ But I wouldn't quite say they have a monopoly of the term. Where there is no risk of misunderstanding, it's fine to use the term. Mathematicians' variable is different still, but there's very little risk of misunderstanding. I'm far less cautious about using variable when I'm talking to you, because I know you won't be confused, than I would be when talking to a newbie, who may be. When two people use the same words, but their understanding of them are slightly different, it's often easier to change the terminology than it is to break people's preconceptions and connotations. And BTW, applying it to Python is not inconsistent with its usage in Pascal. In the technical vocabulary of Pascal, a variable is anything that can appear on the left hand side of an assignment. The analogous term in C is lvalue. Sure, but if you think Python variables behave like Pascal variables, you'll may be surprised by Python and wonder why integer arguments are call by value and list arguments are call by reference... -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On Sun, May 8, 2011 at 4:16 PM, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: On Sun, 08 May 2011 10:54:57 +1200, Gregory Ewing greg.ew...@canterbury.ac.nz declaimed the following in gmane.comp.python.general: What would *you* call a[i]? Depending upon the nature of the beast, I'd be tempted to call it a fully qualified name or a partially qualified name a = [1, 2, 4, (c, d, e)] Why is an integer more or less important than a tuple? a[3] is no less qualified than a[2]; each of them points to an object. One of those objects happens to contain other objects. What if you had: stdio = [stdin, stdout, stderr] They might be 'file' objects, or they might be integers (unlikely in Python), or they could be pipes or other file-like objects, or they might be some kind of special tee object that contains two file objects. Let's say your standard I/O uses the notation stdout.write('message') and that you have a subclass of tuple that will apply the . operator to all its members (is that possible in Python? If not, pretend it is). You could then execute stdio[1]=(stdout,teeobject) to easily copy your screen output to another file. At this point, you can actually pretend that stdio[0] and stdio[1] are identical objects, but you can use stdio[1][1] and you can't use stdio[0][1] - which means that, per your definition, one of them is only partially qualified. As Inigo Montoya said, there is too much - let me sum up. Lists/tuples and integers are equally objects, so whether or not you have a 'name' is not affected by what type of object it points to. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
Steven D'Aprano wrote: Since you haven't explained what you think is happening, I can only guess. Let me save you from guessing. I'm thinking of a piece of paper with a little box on it and the name 'a' written beside it. There is an arrow from that box to a bigger box. +-+ +---+ | | a | --+| | +---+ | | +-+ There is another little box labelled 'b'. After executing 'a = b', both little boxes have arrows pointing to the same big box. +-+ +---+ | | a | --+| | +---+ | | +-+ ^ +---+ | b | --+---| +---+ In this model, a reference is an arrow. Manipulating references consists of rubbing out the arrows and redrawing them differently. Also in this model, a variable is a little box. It's *not* the same thing as a name; a name is a label for a variable, not the variable itself. It seems that you would prefer to eliminate the little boxes and arrows and write the names directly beside the objects: +-+ a | | | | b | | +-+ +-+ c | | | | | | +-+ But what would you do about lists? With little boxes and arrows, you can draw a diagram like this: +---+ +---+ a | --+-| | +-+ +---+ +---+ | | | --+-| | +---+ | | | | +-+ +---+ (Here, the list is represented as a collection of variables. That's why variables and names are not the same thing -- the elements of the list don't have textual names.) But without any little boxes or arrows, you can't represent the list itself as a coherent object. You would have to go around and label various objects with 'a[0]', 'a[1]', etc. +-+ a[0] | | | | | | +-+ +-+ a[1] | | | | | | +-+ This is not very satisfactory. If the binding of 'a' changes, you have to hunt for all your a[i] labels, rub them out and rewrite them next to different objects. It's hardly conducive to imparting a clear understanding of what is going on, whereas the boxes-and-arrows model makes it instantly obvious. There is a half-way position, where we use boxes to represent list items, but for bare names we just draw the arrow coming directly out of the name: +---+ a -| | +-+ +---+ | | | --+-| | +---+ | | | | +-+ +---+ But this is really just a minor variation. It can be a useful shorthand, but it has the drawback of making it seem as though the binding of a bare name is somehow different from the binding of a list element, when it isn't really. Finally, there's another benefit of considering a reference to be a distinct entity in the data model. If you think of the little boxes as being of a fixed size, just big enough to hold a reference, then it's obvious that you can only bind it to *one* object at a time. Otherwise it might appear that you could draw more than one arrow coming out of a name, or write the same name next to more than one object. It seems to me that the boxes-and-arrows model, or something isomorphic to it, is the most abstract model you can make of Python that captures everything necessary to reason about it both easily and correctly. -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
Hans Georg Schaathun wrote: You cannot reference nor manipulate a reference in python, and that IMHO makes them more abstract. You can manipulate them just fine by moving them from one place to another: a = b You can use them to get at stuff they refer to: a = b.c a[:] = b[:] You can compare them: if a is b: ... That's about all you can do with pointers in Pascal, and I've never heard anyone argue that Pascal pointers are any more or less abstract than any other piece of data in that language. As for referencing a reference, you can't really do that in Pascal either, at least not the way you can in C, because (plain) Pascal doesn't have an address-of operator. The only way to get a pointer to a pointer in Pascal is to heap-allocate a single pointer, which isn't normally a very useful thing to do. -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On Sat, May 7, 2011 at 7:21 PM, Gregory Ewing greg.ew...@canterbury.ac.nz wrote: Hans Georg Schaathun wrote: You cannot reference nor manipulate a reference in python, and that IMHO makes them more abstract. You can manipulate them just fine by moving them from one place to another: I think manipulate here means things like pointer arithmetic, which are perfectly normal and common in C and assembly, but not in languages where they're references. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
John Nagle wrote: Such tuples are still identical, even if they contain identical references to immutable objects. The point is you'd have to do the comparison only one level deep, so it wouldn't be exactly the same as == on tuples. -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On Thu, 05 May 2011 07:43:59 +1000, Ben Finney wrote: ‘x’ is a name. Names are bound to values. Talk of “variable” only confuses the issue because of the baggage carried with that term. But to use 'name' as a complete replacement for 'variable', you have to stretch it to include things like a[i], b.c, e.f(x).g[i:j].k, etc. which goes rather a long way beyond the everyday meaning of the word. In Python I use 'variable' to mean more or less 'something that can be assigned to', which accords with the way it's used in relation to many other languages, and doesn't suggest any restriction to things named by a single identifier. But the data model of Python doesn't fit well with the ideas that the term “variable” connotes for most programmers: Seems to me that anyone taking that connotation from it has not yet been sufficiently educated about the Python data model itself. Part of explaining that data model consists of instilling the very idea that the things in Python that are analogous to variables in other languages only refer to data rather than containing the actual data. Saying “variable” and “has the value” But I don't say has a value, I say refers to. -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
Andreas Tawn wrote: If True and False: waveFunction.collapse(cat) Call-by-entanglement would be interesting. Anything that the callee does to the parameter would affect the caller, but you would only be able to tell by examining a trace of the output afterwards. -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
Grant Edwards wrote: if you feel it just right and you have just the right synchro-mesh setup, you can slide from 3rd into 4th without every touching the clutch peddle... and if that isn't automatic, I don't know what is No, that's _not_ automatic if you have to do it yourself. It's automatic when it happens without user-intervention. Does it count if the transmission is activated by saying Home, Jeeves? -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On 2011-05-07, Gregory Ewing greg.ew...@canterbury.ac.nz wrote: Grant Edwards wrote: if you feel it just right and you have just the right synchro-mesh setup, you can slide from 3rd into 4th without every touching the clutch peddle... and if that isn't automatic, I don't know what is No, that's _not_ automatic if you have to do it yourself. It's automatic when it happens without user-intervention. Does it count if the transmission is activated by saying Home, Jeeves? Only if your name is Bertie Wooster. -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
Gregory Ewing wrote: because modern architectures are so freaking complicated that it takes a computer to figure out the best instruction sequence certainly is, I would not imagine one who writes on scraps of paper :D :D :D -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
Gregory Ewing greg.ew...@canterbury.ac.nz writes: On Thu, 05 May 2011 07:43:59 +1000, Ben Finney wrote: ‘x’ is a name. Names are bound to values. Talk of “variable” only confuses the issue because of the baggage carried with that term. But to use 'name' as a complete replacement for 'variable', I don't propose doing that. In Python I use 'variable' to mean more or less 'something that can be assigned to', which accords with the way it's used in relation to many other languages, and doesn't suggest any restriction to things named by a single identifier. No, I think not. The term “variable” usually comes with a strong expectation that every variable has exactly one name. Your more broad usage would need to be carefully explained to newbies anyway, so I don't see a good reason to use the term “variable” for that either. Seems to me that anyone taking that connotation from it has not yet been sufficiently educated about the Python data model itself. Yes, of course. But why not meet such newcomers partway, by not confusing the issue with a term which needs such delicate treatment? Saying “variable” and “has the value” But I don't say has a value, I say refers to. Good for you. Most don't. -- \ Q: “I've heard that Linux causes cancer...” Torvalds: “That's a | `\ filthy lie. Besides, it was only in rats and has not been | _o__) reproduced in humans.” —Linus Torvalds | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
In article 87aaeymfww@benfinney.id.au, Ben Finney ben+pyt...@benfinney.id.au wrote: No, I think not. The term âvariableâ usually comes with a strong expectation that every variable has exactly one name. Heh. You've never used common blocks in Fortran? Or, for that matter, references in C++? I would call either of those two names for the same variable. -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
Chris Angelico wrote: I think manipulate here means things like pointer arithmetic, I don't believe that allowing arithmetic on pointers is a prerequisite to considering them first-class values. You can't do arithmetic on pointers in Pascal, for example, but nobody argues that Pascal pointers are not values. -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
Ben Finney wrote: No, I think not. The term “variable” usually comes with a strong expectation that every variable has exactly one name. I would say that many variables don't have names *at all*, unless you consider an expression such as a[i] to be a name. And if you *do* consider that to be a name, then clearly one variable can have a great many names. What would *you* call a[i]? -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On Sun, May 8, 2011 at 8:54 AM, Gregory Ewing greg.ew...@canterbury.ac.nz wrote: Ben Finney wrote: No, I think not. The term “variable” usually comes with a strong expectation that every variable has exactly one name. I would say that many variables don't have names *at all*, unless you consider an expression such as a[i] to be a name. And if you *do* consider that to be a name, then clearly one variable can have a great many names. What would *you* call a[i]? a is a variable; i is a variable; a[i] is an expression. It's not a single name, and if you had two variables i and j with the same value, nobody would disagree that a[i] and a[j] ought to be the same thing. That's the whole point of arrays/lists/etc/etc. But if you want to fry your noggin, wrap your head around REXX's compound variables: a=5 b=3 array.a.b=Hello /* see, this is a two-dimensional array */ c=63/10 array.c=world! /* see, we can have non-integers as array indices */ d=a+1 result = array.a.b, array.d.b /* Hello, world! */ So what is a name in REXX? You have to evaluate the compound variable as a set of tokens, then evaluate the whole thing again, and is that the name? Because the resulting name might not be a valid identifier... Yep, it's good stuff. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
Gregory Ewing greg.ew...@canterbury.ac.nz writes: Ben Finney wrote: No, I think not. The term “variable” usually comes with a strong expectation that every variable has exactly one name. I would say that many variables don't have names *at all*, unless you consider an expression such as a[i] to be a name. Again, our disagreement is not over the behaviour of Python, but over what an average newcomer to Python can be expected to understand by the term “variable” from its usage elsewhere in programming. What would *you* call a[i]? What *I* would call that isn't relevant to the point. I do think it's even more misleading to call that “a variable”, though, since it's not what the Python docs call a variable and it's not what an average newcomer would call a variable. It's a reference. So is ‘a’, so is ‘i’; names are a special kind of reference. In Python, references are how we get at objects within our code, and names are one kind of reference. -- \ “Not using Microsoft products is like being a non-smoker 40 or | `\ 50 years ago: You can choose not to smoke, yourself, but it's | _o__) hard to avoid second-hand smoke.” —Michael Tiemann | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On Sat, 07 May 2011 21:21:45 +1200, Gregory Ewing wrote: Hans Georg Schaathun wrote: You cannot reference nor manipulate a reference in python, and that IMHO makes them more abstract. You can manipulate them just fine by moving them from one place to another: a = b I see no reference there, nor do I see any moving taking place. What I see is a name binding operation. What is happening is that the name a is being bound to the object b (or to be precise, to whatever object is currently bound to name b). Since you haven't explained what you think is happening, I can only guess. My guess is that you are thinking about some implementation of the Python VM which uses some sort of reference internally. Perhaps it's CPython, which uses pointers, or some C++ implementation which actually uses an indirect pointer-like data structure called reference, or maybe even some old-time FORTRAN I implementation that simulates pointers with integer indexes into a fixed size array. It could be anything. But whatever you're thinking of, it's not the behaviour of *Python* code, it's behaviour of the Python virtual machine's implementation. It astonishes me how hard it is to distinguish between abstraction levels when discussing computer languages. We don't have this problem in other fields. Nobody talking about (say) Solitaire on a computer would say: Blat the pixels in the rect A,B,C,D to the rect E,F,G,H. That will free up the Ace of Spades and allow you to memcopy the records in the far right column of the tableau into the foundation. but when it comes to high-level computer languages like Python, we do the equivalent *all the time*. (I include myself in this.) And people get into (often angry) arguments over definitions, when what they're really arguing about is what is happening at different abstraction levels. A simplified view: At the Python level: binding of objects to names. No data is copied except by use of a direct copy instruction, e.g. slicing. At the Python VM level: objects pushed and popped from a stack. At the VM implementation level: Name binding may be implemented by copying pointers, or some other reference, in some data structure representing name spaces. Or by any other mechanism you like, so long as the behaviour at the Python level is the same. At the assembly language level: memory is copied from one address to another. At the hardware level: we usually describe bit manipulation in terms of binary AND, XOR and OR, but even that may be an abstraction: it's possible that the only binary op physically used by the machine is NAND. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
Steven D'Aprano wrote: Nobody talking about (say) Solitaire on a computer would say: Blat the pixels in the rect A,B,C,D to the rect E,F,G,H. That will free up the Ace of Spades and allow you to memcopy the records in the far right column of the tableau into the foundation. but when it comes to high-level computer languages like Python, we do the equivalent *all the time*. I find exception to that argument. That is an example of the bogus analogy fallacy. (I am offering this in friendship, actually). The two cases have nothing to do with one another, do not affect one another directly or indirectly, and are not helpful for comparison sake. Analogies are generally not helpful in discussion and ought to be avoided generally... except for entertainment sake... and frankly I have found many of your analogies most entertaining (and creative) ! Second point, we seldom do anything *all the time* / this is a fallacy that presupposes extreme references, as we think about the argument; extreme exageration is not helpful... may or may not be rightly extreme, and may or may not be relevant. What can be said (about the argument) is that we sometimes waste time arguing over abstraction layers with limited cross-dependent understanding. (I include myself in this.) (myself, as well) ... the humility is appreciated. And people get into (often angry) arguments over definitions, when what they're really arguing about is what is happening at different abstraction levels. Sometimes. More often than not, folks are not really angry (I am seldom angry at my computer terminal... its one of the places where I relax, learn, communicate, and relate with other computer scientists who enjoy what they do because its enjoyable. I do agree with you that we all sometimes talk past each other because we're arguing from within a 'different' level of abstraction. kind regards, m harris -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On May 8, 7:17 am, Steven D'Aprano steve +comp.lang.pyt...@pearwood.info wrote: On Sat, 07 May 2011 21:21:45 +1200, Gregory Ewing wrote: Hans Georg Schaathun wrote: You cannot reference nor manipulate a reference in python, and that IMHO makes them more abstract. You can manipulate them just fine by moving them from one place to another: a = b I see no reference there, nor do I see any moving taking place. What I see is a name binding operation. What is happening is that the name a is being bound to the object b (or to be precise, to whatever object is currently bound to name b). Since you haven't explained what you think is happening, I can only guess. My guess is that you are thinking about some implementation of the Python VM which uses some sort of reference internally. Perhaps it's CPython, which uses pointers, or some C++ implementation which actually uses an indirect pointer-like data structure called reference, or maybe even some old-time FORTRAN I implementation that simulates pointers with integer indexes into a fixed size array. It could be anything. But whatever you're thinking of, it's not the behaviour of *Python* code, it's behaviour of the Python virtual machine's implementation. It astonishes me how hard it is to distinguish between abstraction levels when discussing computer languages. We don't have this problem in other fields. Nobody talking about (say) Solitaire on a computer would say: Blat the pixels in the rect A,B,C,D to the rect E,F,G,H. That will free up the Ace of Spades and allow you to memcopy the records in the far right column of the tableau into the foundation. but when it comes to high-level computer languages like Python, we do the equivalent *all the time*. It has to be so -- because the Turing machine like the modern computer is an unbelievable abstraction squasher. Yes unbelievable in the sense that people simply cant come to terms with this. [Witness your It astonishes me... Harris: I take exception.. etc] The modern computer (von Neumann) - self-modifying code - Data=Code - Undecidability (Halting problem) - Consistency XOR Completeness (Godels theorem(s)) - Leaky Abstractions as inevitable If anyone thinks Godels theorems are easy trivial, he probably does not know what he is talking about, Yet we think that computers are easy to understand? [Ive personally witnessed PhDs in computer science not appreciate compilers' inability to do certain things, and yet they could go and take a bunch of lectures on the halting problem. What they understand is anybody's guess :-) ] Coming back to topic: The argument (about bindings, variables etc) arises because python (like lisp) is an imperative language masquerading as a functional one. Such arguments dont arise in Haskell or in assembly language. They arise and are tolerable in C. They are terrible in C++ because all the abstractions are built to leak. Where python sits in this (circular) spectrum is an interesting question (and I watch the arguments with much interest) -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On 2011-05-05, Chris Angelico ros...@gmail.com wrote: On Fri, May 6, 2011 at 1:29 AM, Roy Smith r...@panix.com wrote: Hey, let's override operator,() and have some fun Destroying sanity, for fun and profit. I was thinking more along the lines of stuff like combining the envelope pattern (an interface class containing a pointer to an implementation) with template classes to create type-safe polymorphic types with specializable, decoupled implementations. A Python programmer just feels depressed that anyone could have a need for such innovations, though. ;) -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
John Nagle wrote: A reasonable compromise would be that is is treated as == on immutable objects. (Note: I have no dog in this fight, I would be happy with a changed is or with the current one -- leaky abstractions are fine with me, provided I am told *when* they may -- or sometimes may not -- leak. :-) ) On 5/5/2011 3:06 AM, Gregory Ewing wrote: That wouldn't work for tuples, which can contain references to other objects that are not immutable. On Thu, May 5, 2011 at 9:41 AM, John Nagle na...@animats.com wrote: Such tuples are still identical, even if they contain identical references to immutable objects. In article mailman.1196.1304613911.9059.python-l...@python.org Ian Kelly ian.g.ke...@gmail.com wrote: a = (1, 2, [3, 4, 5]) b = (1, 2, [3, 4, 5]) a == b True a is b # Using the proposed definition True I believe that John Nagle's proposal would make a is b false, because while a and b are both immutable, they contain *different* refernces to *mutable* objects (thus failing the identical references to immutable objects part of the claim). On the other hand, should one do: L = [3, 4, 5] a = (1, 2, L) b = (1, 2, L) then a is b should (I say) be True under the proposal -- even though they contain (identical) references to *mutable* objects. Loosely speaking, we would define the is relation as: (x is y) if and only if (id(x) == id(y) or (x is immutable and y is immutable and (for all components xi and yi of x, xi is yi))) In this case, even if the tuples a and b have different id()s, we would find that both have an immutable type, and both have components -- in this case, numbered, subscriptable tuple elements, but instances of immutable class types like decimal.Decimal would have dictionaries instead -- and thus we would recursively apply the modified is definition to each element. (For tuples, the all components implies that the lengths must be equal; for class instances, it implies that they need to have is-equal attributes, etc.) It's not entirely clear to me whether different immutable classes (i.e., different types) but with identical everything-else should compare equal under this modified is. I.e., today: $ cp /usr/lib/python2.?/decimal.py /tmp/deccopy.py $ python ... sys.path.append('/tmp') import decimal import deccopy x = decimal.Decimal('1') y = deccopy.Decimal('1') print x, y 1 1 x == y False and obviously x is y is currently False: type(x) class 'decimal.Decimal' type(y) class 'deccopy.Decimal' However, even though the types differ, both x and y are immutable [%] and obviously (because I copied the code) they have all the same operations. Since they were both created with the same starting value, x and y will behave identically given identical treatment. As such, it might be reasonable to ask that x is y be True rather than False. [% This is not at all obvious -- I have written an immutable class, and it is pretty easy to accidentally mutate an instance inside the class implementation. There is nothing to prevent this in CPython, at least. If there were a minor bug in the decimal.Decimal code such that x.invoke_bug() modified x, then x would *not* be immutable, even though it is intended to be. (As far as I know there are no such bugs in decimal.Decimal, it's just that I had them in my Money class.)] -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
In article GOmwp.13554$vp.9...@newsfe14.iad harrismh777 harrismh...@charter.net wrote: There may be some language somewhere that does pass-by-reference which is not implemented under the hood as pointers, but I can't think of any... 'cause like I've been saying, way down under the hood, we only have direct and indirect memory addressing in today's processors. EOS. There have been Fortran compilers that implemented modification of variables via value-result rather than by-reference. This is perhaps best illustrated by some code fragments: SUBROUTINE FOO(X, Y) INTEGER X, Y ... X = 3 Y = 4 RETURN SUBROUTINE BAR(A) FOO(A, 0) RETURN might compile to the equivalent of the following C code: void foo(int *x0, int *y0) { int x = *x0, y = *y0; ... *x0 = x; *y0 = y; } void bar(int *a0) { int a = *a0; int temp = 0; foo(a, temp); *a0 = a; } In order to allow both by-reference and value-result, Fortran forbids the programmer to peek at the machinery. That is, the following complete program is invalid: SUBROUTINE PEEK(X) INTEGER X, GOTCHA COMMON /BLOCK/ GOTCHA PRINT *, 'INITIALLY GOTCHA = ', GOTCHA X = 4 PRINT *, 'AFTER X=4 GOTCHA = ', GOTCHA RETURN PROGRAM MAIN INTEGER GOTCHA COMMON /BLOCK/ GOTCHA GOTCHA = 3 PEEK(GOTCHA) PRINT *, 'FINALLY GOTCHA = ', GOTCHA STOP END (It has been so long since I used Fortran that the above may not be quite right in ways other than the one intended. Please forgive small errors. :-) ) The trick in subroutine peek is that it refers to both a global variable (in Fortran, simulated with a common block) and a dummy variable (as it is termed in Fortran) -- the parameter that aliases the global variable -- in such a way that we can see *when* the change happens. If gotcha starts out set to 3, remains 3 after assignment to x, and changes to 4 after peek() returns, then peek() effectively used value-result to change the parameter. If, on the other hand, gotcha became 4 immediately after the assignment to x, then peek() effectively used by-reference. The key take-away here is not so much the trick by which we peeked inside the implementation (although peeking *is* useful in solving the murder mystery we have after some program aborts with a core-dump or what-have-you), but rather the fact that the Fortran language proper forbids us from peeking at all. By forbidding it -- by making the program illegal -- the language provide implementors the freedom to use *either* by-reference or value-result. All valid Fortran programs behave identically under either kind of implementation. Like it or not, Python has similar defined as undefined grey areas: one is not promised, for instance, whether the is operator is always True for small integers that are equal (although it is in CPython), nor when __del__ is called (if ever), and so on. As with the Python-named-Monty, we have rigidly defined areas of doubt and uncertainty. These exist for good reasons: to allow different implementations. -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
In article iq1e0j02...@news2.newsguy.com I wrote, in part: Like it or not, Python has similar defined as undefined grey areas: one is not promised, for instance, whether the is operator is always True for small integers that are equal (although it is in CPython), nor when __del__ is called (if ever), and so on. As with the Python-named-Monty, we have rigidly defined areas of doubt and uncertainty. These exist for good reasons: to allow different implementations. Oops, attribution error: this comes from Douglas Adams rather than Monty Python. -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
Chris Torek wrote: with the Python-named-Monty, we have rigidly defined areas of doubt and uncertainty. These exist for good reasons: to allow different implementations. Oops, attribution error: this comes from Douglas Adams rather than Monty Python. Well, its certainly Monte-esq I like it, whoever said it. -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On Sat, May 7, 2011 at 5:25 AM, harrismh777 harrismh...@charter.net wrote: Chris Torek wrote: with the Python-named-Monty, we have rigidly defined areas of doubt and uncertainty. These exist for good reasons: to allow different implementations. Oops, attribution error: this comes from Douglas Adams rather than Monty Python. Well, its certainly Monte-esq I like it, whoever said it. Same style of humour, they both derived significantly from Spike Milligan and The Goon Show. That particular quote relates to the famous computer that calculated the number 42, which - to drag this, kicking and screaming, back to some semblance of on-topicness - was clearly built with a view to conserving programmer time at the expense of execution time. I don't understand why they didn't just recode the heavy computation in C and cut it down to just a few thousand years... Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On Wed, 04 May 2011 16:49:25 -0500, harrismh777 harrismh...@charter.net wrote: : Folks seem to think that because they are doing abstraction at a : high-level (well, they never maybe programmed at a lower level) that : abstraction somehow 'requires' a high level language. (not true) I never said 'requires', but when you do high-level modelling, low-level detail is a distraction. Using a low-level language for abstract modelling is therefore harder than it needs to be. : Today, high-level languages like Python (and others) allow programmers : to place some of their abstraction into their source code directly. This : does not make the high-level language any more 'suited' to abstraction : than any other lower-level language; because the abstraction is a mental : process not a language feature. It all ends up in assembly and machine : code. Indeed, except for the contradiction. The fact that you can put more of your abstraction into the source code means that it is better suited to abstraction. Mental processes depend on language; at least when you need to communicate the output. That language does not have to be computer readable (as is the case for your float charts etc). We may very well use a stack of languages and models at different levels of abstraction, but when you move down the stack you are moving away from abstraction and into implementation. C is very rarely suitable at the top of this stack. When I say that C is ill-suited for abstraction, I am not implying that it is ill-suited for implementing according to an abstract model. If you need human input in the lower layers of abstraction, C is a good choice. Using manual work to move down the layers of abstraction is possible, and given sufficient man-power should give the better result, but relying on human input when the work can be automated is ridiculously expensive. Now, python is only one level above C in abstraction, but that's a different matter. -- :-- Hans Georg -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On Wed, 04 May 2011 20:11:02 -0500, harrismh777 harrismh...@charter.net wrote: : A reference is a pointer (an address). : : A value is memory (not an address). Sure, and pointers (from a hardware or C perspective) are memory, hence pointers are values. -- :-- Hans Georg -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
Hans Georg Schaathun wrote: With the references being purely abstract entities and not data objects, It's not clear to me that references are any more abstract than objects, or to put it another way, that objects are any less abstract than references. After all, in normal Python usage you never actually *see* an object -- at best you see some string of characters resulting from the str() or repr() of an object. The object is a mental construct we use to make sense of the behaviour we're seeing, as are references. If you were to look inside the interpreter closely enough to see the concrete representations of objects -- the bit patterns in memory making them up -- then you would also be able to see the bit patterns making up the references. -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
harrismh777 wrote: 'C' is still the best high-level language on that processor. Some would argue that C is actually better than assembler these days, because modern architectures are so freaking complicated that it takes a computer to figure out the best instruction sequence. :-( -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On Thu, May 5, 2011 at 7:08 PM, Gregory Ewing greg.ew...@canterbury.ac.nz wrote: harrismh777 wrote: 'C' is still the best high-level language on that processor. Some would argue that C is actually better than assembler these days, because modern architectures are so freaking complicated that it takes a computer to figure out the best instruction sequence. :-( I use C to hint to the compiler as to what I'd like it to write a program to do. It does all the writing, I just make some vague suggestions - which it's free to ignore if it chooses. GCC and me, we get along jess fine... ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
harrismh777 wrote: That is the $10,000,000 dollar problem... how to extricate ourselves from the von Neumann processor. *Everthing* comes down to that... its hilarious to hear folks talk about lambda the ultimate (especially those guys on Lambda the Ultimate) when there is no such thing until such time as we have lambda the hardware architecture. I think there are fundamental problems that go beyond the issue of hardware design. It's easy to reason about a program that does things one step at a time, much harder when lots of things are happening at once. Whether you express the program using lambda calculus or a Turing machine doesn't change that fact. -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
John Nagle wrote: A reasonable compromise would be that is is treated as == on immutable objects. That wouldn't work for tuples, which can contain references to other objects that are not immutable. -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
harrismh777 wrote: 'C' does provide for pointers which are used by all 'C' programmers to firmly provide pass-by-reference in their coding Yes, but when they do that, they're building an abstraction of their own on top of the facilities provided by the C language. C itself has no notion of pass-by-reference. If it did, the programmer would be able to use it directly instead of having to insert and * operators himself. -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On Thu, 05 May 2011 20:55:36 +1200, Gregory Ewing greg.ew...@canterbury.ac.nz wrote: : It's not clear to me that references are any more abstract : than objects, or to put it another way, that objects are : any less abstract than references. : : After all, in normal Python usage you never actually : *see* an object Sure, but you can refer directly to objects, pass objects around, and refer to individual objects. This is abstract in the sense that it is far removed from the memory representation. However, the concept of a reference appears only when you explain how objects are handled (semantics). You cannot reference nor manipulate a reference in python, and that IMHO makes them more abstract. -- :-- Hans Georg -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
John Nagle wrote: On 5/4/2011 5:46 PM, harrismh777 wrote: Or, as stated earlier, Python should not allow 'is' on immutable objects. A reasonable compromise would be that is is treated as == on immutable objects. I foresee trouble testing among float(5), int(5), Decimal(5) ... Mel. -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On Thu, May 5, 2011 at 9:44 PM, Mel mwil...@the-wire.com wrote: John Nagle wrote: On 5/4/2011 5:46 PM, harrismh777 wrote: Or, as stated earlier, Python should not allow 'is' on immutable objects. A reasonable compromise would be that is is treated as == on immutable objects. I foresee trouble testing among float(5), int(5), Decimal(5) ... Define 'x is y' as 'type(x)==type(y) and isinstance(x,(int,float,tuple,etc,etc,etc)) and x==y' then. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
Tim Roberts wrote: That is not an instance of passing an int by reference. That is an instance of passing an int * by value. The fact that the parameter a in BumpMe happens to be an address is completely irrelevent to the definition of the parameter passing mechanism. C has pass-by-value, exclusively. End of story. Trouble with Turing-complete languages. If it can be done, you can convince a Turing-complete language to do it -- somehow. PL/I was the converse. All parameters were passed by reference, so with some_proc (rocks); the code in some_proc would be working with the address of rocks. If you wanted pass-by-value you wrote some_proc ((rocks)); whereupon the compiler would pass in by reference an unnamed temporary variable whose value was the expression `(rocks)`. I suspect the compiler I used avoided FORTRAN's troubles the same way. Your function could corrupt *a* 4, but it wouldn't corrupt the *only* 4. Mel. -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On Wed, 04 May 2011 15:46:07 -0400, Benjamin Kaplan wrote: On Wed, May 4, 2011 at 3:22 PM, harrismh777 harrismh...@charter.net wrote: [...] Digging down into C should be unnecessary to explain Python. huh? You have to be kidding. Why do you suppose we want it to be open-sourced? Use the force Luke, read the source. If you really want to know how Python is working you *must* dig down into the C code which implements it. The folks who document Python should be able to tell us enough to know how to use the language, but to really 'know' you need the implementation source. Reading the CPython sources will show you how CPython works under the hood, but it has nothing to do with how Python works. There are lots of things that CPython does that Python does not. For instance, the GIL is not a part of Python. Reference counting is not a part of Python. Caching small integers and strings is not a part of Python. Why not read the Jython sources instead of the CPython? It's the same language, after all. More importantly, Python need not be implemented at all. If you're stuck on a desert island without electricity, you could simulate the effect of running any arbitrary Python code merely by understanding the semantics of high-level Python code, without caring the slightest about pointers at the C implementation level, or bit flipping at the hardware level, or von Neumann machines, or ref counting, or garbage collection, or any of a million other implementation details. All you need understand is the declared semantics of the language. Surely I can't be the only one who sometimes tries to work out a tricky bit of Python code by hand-simulating it on pencil and paper? -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On Thu, May 5, 2011 at 10:14 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: More importantly, Python need not be implemented at all. If you're stuck on a desert island without electricity, you could simulate the effect of running any arbitrary Python code merely by understanding the semantics of high-level Python code... http://xkcd.com/505/ Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On Wed, 04 May 2011 14:22:38 -0500, harrismh777 wrote: Here is the thing that everyone forgets... all we have to work with is a von Neumann processor. (same as EDVAC, ENIAC, the VIC20, etc). Actually, this is incorrect. Most processors these days are hybrids between that and either the Harvard or Modified Harvard architecture: http://en.wikipedia.org/wiki/Modified_Harvard_architecture http://en.wikipedia.org/wiki/Harvard_architecture http://en.wikipedia.org/wiki/Von_Neumann_architecture Assembler is still the best language on that processor. Assembly is not a language, it is a generic term for dozens or hundreds of different languages. But in any case, it's not clear what you mean by best language. 'C' is still the best high-level language on that processor. C is better described as a high-level assembler, or a low-level language. It is too close to the hardware to describe it as high-level, it has no memory management, few data abstractions, and little protection. Its silly to claim that one high-level language or another is better suited to complex data abstraction... don't go there. Surely you can't possibly mean that? Surely you don't mean to tell us that the 1957 version of FORTRAN, or unstructured BASIC, or early COBOL, are just as well suited to data abstraction as (say) Haskell? Many implementations of unstructured BASIC didn't even have arrays, only character strings and integers. Or (one of my personal favourites), Apple's Hypertalk? *Everything* is a string in Hypertalk. I love Hypertalk, but good for data abstraction? Don't make me laugh. You should read Paul Graham on the Blub Paradox: http://www.paulgraham.com/avg.html -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On 2011-05-04, John Nagle na...@animats.com wrote: That's a quirk of CPython's boxed number implementation. All integers are boxed, but there's a set of canned objects for small integers. CPython's range for this is -5 to +256, incidentally. That's visible through the is operator. Arguably, it should not be. But that's the sole purpose of the is operator. You either expose those details, or you don't have an is operator at all. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On Thu, 05 May 2011 21:48:20 +1000, Chris Angelico wrote: On Thu, May 5, 2011 at 9:44 PM, Mel mwil...@the-wire.com wrote: John Nagle wrote: On 5/4/2011 5:46 PM, harrismh777 wrote: Or, as stated earlier, Python should not allow 'is' on immutable objects. A reasonable compromise would be that is is treated as == on immutable objects. I foresee trouble testing among float(5), int(5), Decimal(5) ... Define 'x is y' as 'type(x)==type(y) and isinstance(x,(int,float,tuple,etc,etc,etc)) and x==y' then. `is` is supposed to be a *fast* operator, not even slower than equality testing. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On Wed, 04 May 2011 20:11:02 -0500, harrismh777 wrote: These definitions go all the way back before the 8080, or the 6502, 8 bit processors. Pass by reference has 'always' meant pass by using a memory address (indirect addressing); a reference has always been a memory pointer. That's not a definition. That's an implementation. Some day, we'll be using quantum computers without memory addresses, or DNA computers, or some version of Babbage's Difference Engine (perhaps a trillion of them in the volume of a match-head, tiny nano computing devices... who knows?). Whatever it is, whether or not it has concepts of memory address or memory pointer, it will still be possible to represent data indirectly via *some* mechanism. If I call a function in C, and pass-by-value, the data's 'value' is placed on the stack in a stack-frame, as a 'value' parm... its a copy of the actual data in memory. Correct. If I call a function in C, and pass-by-reference, the data's 'address' C doesn't do pass by reference. There is no way to declare a parameter to a function as a by-reference parameter. You can only simulate it by hand, by passing a pointer as data, pointing to what you *really* want as data, and dereferencing it yourself. But the pointer itself is passed by value: the address is copied onto the stack, just like any other piece of data would be. (The Python equivalent is to pass a list containing the object. If you want call-by-reference behaviour without the convenience of language support for it, you can have it.) Pascal, on the other hand, does do pass by reference. If you declare a var parameter, you then call the function with the variable you intend, and the compiler handles everything: function foo(x: int, var y: int): int; begin foo := x + y; y := 0; x := 0; end; a := 1; b := 2; c := foo(a, b); After calling foo, the variable a remains 1, but the variable b is now 0. The compiler is smart enough to figure out what to do behind the scenes to make it all work. We're not discussing what you, the coder, can do. Given any Turing- complete language, you can (with sufficient cleverness and hard-work) do anything any other Turing-complete language can do. We're discussing what the compiler does, and for C, that is purely call by value. Let me put it this way... old, unstructured BASIC has GOTOs and line numbers, correct? And Python doesn't, correct? But you could write a BASIC interpreter in Python, and call that interpreter from your Python code... therefore Python has line numbers and GOTOs, no? No. Of course not. We're discussing *language features*, and GOTO is not a language feature of Python. Neither is call by reference a language feature of C, or Python either for that matter, but it is a language feature of VB and Pascal. The only difference between the two scenarios is that writing a BASIC interpreter is a tad harder than dereferencing a pointer, but that's just a matter of degree, not of kind. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On 2011-05-05, harrismh777 harrismh...@charter.net wrote: Grant Edwards wrote: The pass by value and pass by reference parameter passing mechanisms are pretty well defined, and C uses pass by value. Yeah, that's kind-a funny, cause I'm one of the guys (old farts) that helped define them I give up. You don't seem to understand the C language defintion or what is commonly meant by pass by reference. -- Grant Edwards grant.b.edwardsYow! Inside, I'm already at SOBBING! gmail.com -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On 2011-05-05, Gregory Ewing greg.ew...@canterbury.ac.nz wrote: harrismh777 wrote: 'C' does provide for pointers which are used by all 'C' programmers to firmly provide pass-by-reference in their coding Yes, but when they do that, they're building an abstraction of their own on top of the facilities provided by the C language. I've pointed that out to him. He's talking about what _he_ does in his program. We're talking about the C language definition and what the compiler does. C itself has no notion of pass-by-reference. Exactly. C is pass by value. If it did, the programmer would be able to use it directly instead of having to insert and * operators himself. That's what I was trying to say, but probably not as clearly. The operatore returnas a _value_ that the OP passes _by_value_ to a function. That function then uses the * operator to use that value to access some data. -- Grant Edwards grant.b.edwardsYow! DIDI ... is that a at MARTIAN name, or, are we gmail.comin ISRAEL? -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On 2011-05-05, harrismh777 harrismh...@charter.net wrote: Tim Roberts wrote: The fact that the parameter a in BumpMe happens to be an address is completely irrelevent to the definition of the parameter passing mechanism. C has pass-by-value, exclusively. End of story. Yeah, Tim, I know... but that's my entire point in a nut-shell... whether the language is pass-by-value or pass-by-reference has less to do with how it is 'defined' (its mechanism--- indirection and stack) No, whether the _language_ is pass by value or pass-by-reference has _entirely_ to do with it's definition. and more to do with how it is routinely used with the standard features it provides--- in this case memory indirection--- as pointers. Now you're talking about how you can implement higher level constructs using a language that doesn't directly implement such constructs. You might as well say that C is a linked-list language like Lisp since you can write a linked list implementation in C. If you said that you'd be just as wrong as saying that C uses call-by-reference. -- Grant Edwards grant.b.edwardsYow! I want another at RE-WRITE on my CEASAR gmail.comSALAD!! -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On 2011-05-05, Gregory Ewing greg.ew...@canterbury.ac.nz wrote: Hans Georg Schaathun wrote: Is transmission by name the same as call by object? No, it's not. With call-by-name, the caller passes a small function (known as a thunk) that calculates the address of the parameter. Every time the callee needs to refer to the parameter, it evaluates this function. This allows some neat tricks, but it's massive overkill for most uses. It also is a very good source of surprising bugs. -- Grant Edwards grant.b.edwardsYow! I feel like I'm at in a Toilet Bowl with a gmail.comthumbtack in my forehead!! -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On 2011-05-05, harrismh777 harrismh...@charter.net wrote: Dennis Lee Bieber wrote: We do not consider passing a pointer as*by value* because its an address; by definition, that is pass-by-reference. We are not passing To most of the world, pass-by-reference means the COMPILER, not the PROGRAMMER is obtaining and passing the address, and the compiler also always dereferences the passed value... The programmer has no control over whether to operate on the address or the data referenced by the address. Who is most of the world ? Pretty much everybody except you. Please see: http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8a.doc%2Flanguage%2Fref%2Fcplr233.htm Yea, I read that. It doesn't support your argument. It agrees with the rest of the world. -- Grant Edwards grant.b.edwardsYow! I need to discuss at BUY-BACK PROVISIONS gmail.comwith at least six studio SLEAZEBALLS!! -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On 2011-05-05, Gregory Ewing greg.ew...@canterbury.ac.nz wrote: harrismh777 wrote: 'C' is still the best high-level language on that processor. Some would argue that C is actually better than assembler these days, because modern architectures are so freaking complicated that it takes a computer to figure out the best instruction sequence. :-( Been there, done that. Many years ago, it took me more than a week (and required the help of an ARM instruction set guru) to come up with an assembly language IP checksum routine for the ARM that out-performed the somewhat naive NetBSD C version. When we switched to the FreeBSD stack (and a newer compiler) a few years later, my assembly code got tossed out because was no longer any faster than the C version. -- Grant Edwards grant.b.edwardsYow! Half a mind is a at terrible thing to waste! gmail.com -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
In article ipubhb$e4q$2...@reader1.panix.com, Grant Edwards invalid@invalid.invalid wrote: That's what I was trying to say, but probably not as clearly. The operatore returnas a _value_ that the OP passes _by_value_ to a function. That function then uses the * operator to use that value to access some data. Then, of course, there's references in C++. I think it's fair to call the following call by reference in the sense we're talking about it here. void f(int i) { i = 5; } int i = 42; f(i); Of course, C++ lets you go off the deep end with abominations like references to pointers. Come to think of it, C++ let's you go off the deep end in so many ways... -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On 2011-05-05, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Wed, 04 May 2011 14:22:38 -0500, harrismh777 wrote: Here is the thing that everyone forgets... all we have to work with is a von Neumann processor. (same as EDVAC, ENIAC, the VIC20, etc). Actually, this is incorrect. Most processors these days are hybrids between that and either the Harvard or Modified Harvard architecture: http://en.wikipedia.org/wiki/Modified_Harvard_architecture http://en.wikipedia.org/wiki/Harvard_architecture http://en.wikipedia.org/wiki/Von_Neumann_architecture And a lot of the are still full-up Harvard architecture (e.g. the entire Atmel AVR family and Intel 8051 family for example). -- Grant Edwards grant.b.edwardsYow! When this load is at DONE I think I'll wash it gmail.comAGAIN ... -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
Steven D'Aprano wrote: You should read Paul Graham on the Blub Paradox: http://www.paulgraham.com/avg.html Excellent-! ... thanks, fun article. ... where is that lisp manual anyway? ... oh, yeah, emacs! :) -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
In article 4dc29cdd$0$29991$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: C is better described as a high-level assembler, or a low-level language. It is too close to the hardware to describe it as high-level, it has no memory management, few data abstractions, and little protection. +1 I (and most people who really know C and the specific hardware architecture they're working on) should be able to look at a C program and (modulo optimization) pretty much be able to write down the generated assembler by hand. In fact, I used to do exactly that. I was once working on M-6800 hardware (8/16-bit microprocessor). I used to write out procedures in C, then hand-compile it into assembler code (and leave the C code as a comment). I wasn't a true masochist, however. I did let an assembler convert it to hex for me before I keyed it in :-) On the other hand, trying to do that for something like C++ is damn near impossible. There's too much stuff that happens by magic. Creation (and destruction) of temporary objects. Exception handling. RTTI. Not to mention truly black magic like template expansion. -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On Wed, 04 May 2011 14:58:38 -0500, harrismh777 wrote: Benjamin Kaplan wrote: CPython is implemented in C because that's the language chosen. Python is also implemented in Java, C#, Python, and several other languages. True enough. If I used Jython, I would want to take a look at those sources... as well as the Java sources... which were wrtten in, um, C. No, Java sources are written in Java. That's why they're *Java* sources. Perhaps you mean that the Java compiler is written in C? Highly unlikely: Java compilers have been self-hosting for many years now. http://en.wikipedia.org/wiki/Self-hosting -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On Wed, 04 May 2011 16:22:42 -0600, Ian Kelly wrote: However, I hope we can all agree that pass-by-pointer shares certain features with both pass-by-value and pass-by-reference, and there are perfectly reasonable arguments for lumping it in either category, yes? *cries* Please don't invent another pass by foo term Seriously though, pass by foo refers to what the compiler or interpreter does when you, the coder, call a function with some variable, say, x: f(x) It is not referring to what you, the coder, does when you want to pass an indirect reference of some sort to a chunk of data to some function. In many languages, you would use a pointer, and write the function call something like this: f(^x) (using Pascal's up-arrow notation for pointer to). Such pass by pointer is a tactic used by the coder, as opposed to a language feature. I believe this distinction between what the compiler does, and what the coder does, is at the heart of much confusion. Pointers that are passed as arguments are themselves data, just as much as ints or floats, or (in languages that have first-class functions) functions. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On 2011-05-05, Roy Smith r...@panix.com wrote: Of course, C++ lets you go off the deep end with abominations like references to pointers. Come to think of it, C++ let's you go off the deep end in so many ways... But you can do some really cool stuff in the deep end. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On Thu, 05 May 2011 14:14:22 +, Grant Edwards wrote: On 2011-05-05, harrismh777 harrismh...@charter.net wrote: Grant Edwards wrote: The pass by value and pass by reference parameter passing mechanisms are pretty well defined, and C uses pass by value. Yeah, that's kind-a funny, cause I'm one of the guys (old farts) that helped define them I give up. You don't seem to understand the C language defintion or what is commonly meant by pass by reference. In fairness, he's not the only one. M Harris has twice now linked to an IBM site that describes pass-by-reference in C in terms of passing a pointer to the argument you want as the argument. Admittedly, doing so gives you almost the same behaviour, except that you have to dereference the pointers yourself. That's a pretty big difference though, and gets to the core of the argument: it's a bit like arguing that manual cars are fitted with exactly the same automatic transmission as auto cars, it's just that you have to engage the clutch and shift gears yourself. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On Wed, 04 May 2011 09:18:56 -0700, Devin Jeanpierre wrote: On May 4, 9:44 am, Hans Georg Schaathun h...@schaathun.net wrote: : The only twist is that you never get to dereference : pointers in Python, but you can in C. Not much of a twist if you ask : me, but then again, I've been thinking in thismodelfor years. Maybe : I'm brainwashed. :) You are. You explain Python in terms of C. That's useful when you talk to other speakers of C. If you want to explain the language to a broader audience, you should use terminology from the language's own level of abstraction. No, I explained Python in terms of pointers/reference. Python has no pointers or references unless you simulate them yourself using other data types. They exist as implementation details of the Python virtual machine, which is at least two levels below that of Python code. The first is the byte code which runs in the virtual machine; the second is the code in the VM. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
In article 92fsvjfkg...@mid.individual.net, Neil Cerutti ne...@norwich.edu wrote: On 2011-05-05, Roy Smith r...@panix.com wrote: Of course, C++ lets you go off the deep end with abominations like references to pointers. Come to think of it, C++ let's you go off the deep end in so many ways... But you can do some really cool stuff in the deep end. Hey, let's override operator,() and have some fun -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
Steven D'Aprano wrote: Some day, we'll be using quantum computers without memory addresses, [ ... ] it will still be possible to represent data indirectly via *some* mechanism. :) Cool! Pass-by-coincidence! And Python 3 already has dibs on the 'nonlocal' keyword! Mel. -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On 5/5/2011 3:06 AM, Gregory Ewing wrote: John Nagle wrote: A reasonable compromise would be that is is treated as == on immutable objects. That wouldn't work for tuples, which can contain references to other objects that are not immutable. Such tuples are still identical, even if they contain identical references to immutable objects. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On Thu, 05 May 2011 07:43:59 +1000, Ben Finney wrote: Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes: Given the following statement of Python code: x = spam what is the value of the variable x? Mu (無). ‘x’ is a name. Names are bound to values. Talk of “variable” only confuses the issue because of the baggage carried with that term. Yes, good point. Consider me chastised, because I actually knew that. It's just that the term variable is so useful and so familiar that it's easy to use it even for languages that don't have variables in the C/ Pascal/Fortran/etc sense. But the data model of Python doesn't fit well with the ideas that the term “variable” connotes for most programmers: a box, perhaps of a rigid shape (data type) or not, which is labelled ‘x’ and nothing else. For another variable to have an equal value, that value needs to be copied and put in a separate box; or perhaps some special reference to the original needs to be made and placed in a box. Saying “variable” and “has the value” just invites baggage needlessly, and creates many assumptions about Python's data model which has to be un-done, often after much false mental scaffolding has been built on them by the newbie and needs to be dismantled carefully. I've quoted your two paragraphs because I think they're very important, not because I intend arguing. Possibly a first for me :) However Python isn't pass by anything. Nothing gets copied, nothing gets passed; when a function is called with an object as a parameter, the object stays put, and simply gets a new temporary name bound to it for the function's use. This, however, is incorrect. Passing in this sense refers to calling the function with an argument, hence pass by... and call by... are synonyms. The mechanics of how the compiler or interpreter makes arguments available to functions has real consequences at the language level: the calling strategy used by the compiler effects the language semantics. Whatever, a rose by any other name...) Do you really think that roses would be the symbol of romantic love if they were called disgusting stink-weeds of perversion and death? Juliet's point stands, though: they would still smell as sweet, and the term you describe would be unlikely to catch on since it doesn't describe them well at all. Perhaps a counter-example is that of the tomato, which never took off as a food in Europe until people stopped calling them love apples, and thinking that they were deadly poison. Or Chinese Gooseberries, better known by the name thought up by a marketing firm, kiwi fruit. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
Mel wrote: represent data indirectly via*some* mechanism. :) Cool! Pass-by-coincidence! And Python 3 already has dibs on the 'nonlocal' keyword! I was thinking pass-by-osmosis :) -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On 5/5/2011 6:59 AM, Steven D'Aprano wrote: On Thu, 05 May 2011 21:48:20 +1000, Chris Angelico wrote: On Thu, May 5, 2011 at 9:44 PM, Melmwil...@the-wire.com wrote: John Nagle wrote: On 5/4/2011 5:46 PM, harrismh777 wrote: Or, as stated earlier, Python should not allow 'is' on immutable objects. A reasonable compromise would be that is is treated as == on immutable objects. I foresee trouble testing among float(5), int(5), Decimal(5) ... Define 'x is y' as 'type(x)==type(y) and isinstance(x,(int,float,tuple,etc,etc,etc)) and x==y' then. That's close to the right answer. `is` is supposed to be a *fast* operator, not even slower than equality testing. That's an implementation problem. Those are cheap tests at the machine code level. An efficient test looks like this: def istest(a, b) : if id(a) == id(b) : # the cheap address test return(True) if type(x) != type(y) : # cheap binary comparison return(False) if mutable(x) : # the interpreter knows this return(False) return(x == y) # equality test for mutables Probably about 12 machine instructions, and the full == test is only reached for cases in which is now produces wrong answers. It's encouraging that a Google code search finds no matches of if .* is \ or if .* is 1 in Python code. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
Steven D'Aprano wrote: In fairness, he's not the only one. M Harris has twice now linked to an IBM site that describes pass-by-reference in C in terms of passing a pointer to the argument you want as the argument. Admittedly, doing so gives you almost the same behaviour, except that you have to dereference the pointers yourself. That's a pretty big difference though, and gets to the core of the argument: it's a bit like arguing that manual cars are fitted with exactly the same automatic transmission as auto cars, it's just that you have to engage the clutch and shift gears yourself. ... and actually, if you feel it just right and you have just the right synchro-mesh setup, you can slide from 3rd into 4th without every touching the clutch peddle... and if that isn't automatic, I don't know what is man those were the days... now I just press a button that says, Auto 4-wheel Lock, set the gps, and take a nap... :) -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
Grant Edwards wrote: I give up. You don't seem to understand the C language defintion or what is commonly meant by pass by reference. ah, don't give up... here is a link that might help to clarify some of these semantics... me thinks: http://en.wikipedia.org/wiki/Pass_by_reference#Call_by_value kind regards, m harris -- http://mail.python.org/mailman/listinfo/python-list
RE: What other languages use the same data model as Python?
Steven D'Aprano wrote: Some day, we'll be using quantum computers without memory addresses, [ ... ] it will still be possible to represent data indirectly via *some* mechanism. :) Cool! Pass-by-coincidence! And Python 3 already has dibs on the 'nonlocal' keyword! Mel. If True and False: waveFunction.collapse(cat) That's going to be fun ;o) Cheers, Drea -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On Thu, May 5, 2011 at 9:41 AM, John Nagle na...@animats.com wrote: On 5/5/2011 3:06 AM, Gregory Ewing wrote: John Nagle wrote: A reasonable compromise would be that is is treated as == on immutable objects. That wouldn't work for tuples, which can contain references to other objects that are not immutable. Such tuples are still identical, even if they contain identical references to immutable objects. a = (1, 2, [3, 4, 5]) b = (1, 2, [3, 4, 5]) a == b True a is b # Using the proposed definition True a[0] is b[0] True a[1] is b[1] True a[2] is b[2] False a[2].append(6) a (1, 2, [3, 4, 5, 6]) b (1, 2, [3, 4, 5]) a == b False a is b False Thus a and b cannot be used interchangeably even though a is b originally returned True. -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On 2011-05-05, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Thu, 05 May 2011 14:14:22 +, Grant Edwards wrote: On 2011-05-05, harrismh777 harrismh...@charter.net wrote: Grant Edwards wrote: The pass by value and pass by reference parameter passing mechanisms are pretty well defined, and C uses pass by value. Yeah, that's kind-a funny, cause I'm one of the guys (old farts) that helped define them I give up. You don't seem to understand the C language defintion or what is commonly meant by pass by reference. In fairness, he's not the only one. M Harris has twice now linked to an IBM site that describes pass-by-reference in C in terms of passing a pointer to the argument you want as the argument. Admittedly, doing so gives you almost the same behaviour, except that you have to dereference the pointers yourself. That's a pretty big difference though, and gets to the core of the argument: it's a bit like arguing that manual cars are fitted with exactly the same automatic transmission as auto cars, it's just that you have to engage the clutch and shift gears yourself. I like that analogy. My car has an automatic transmission except you have to shift gears yourself with that lever and that it has a clutch operated by that pedal instead of a hydrostatic torque converter. -- Grant Edwards grant.b.edwardsYow! ... bleakness at ... desolation ... plastic gmail.comforks ... -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On 2011-05-05, harrismh777 harrismh...@charter.net wrote: Steven D'Aprano wrote: In fairness, he's not the only one. M Harris has twice now linked to an IBM site that describes pass-by-reference in C in terms of passing a pointer to the argument you want as the argument. Admittedly, doing so gives you almost the same behaviour, except that you have to dereference the pointers yourself. That's a pretty big difference though, and gets to the core of the argument: it's a bit like arguing that manual cars are fitted with exactly the same automatic transmission as auto cars, it's just that you have to engage the clutch and shift gears yourself. ... and actually, if you feel it just right and you have just the right synchro-mesh setup, you can slide from 3rd into 4th without every touching the clutch peddle... That's possible on pretty much any modern automotive or small-truck transmission, and it's not really that hard to do. I can go from 1st up to 5th and back down to 1st without touching the clutch. I don't as a habit do it, because it puts unnecessary wear on the syncros (and I've had cars with pretty weak syncros -- Alfa-Romeo Spyders were famous for the 2nd gear syncro wearing out). and if that isn't automatic, I don't know what is No, that's _not_ automatic if you have to do it yourself. It's automatic when it happens without user-intervention. Now I think you're trolling... -- Grant Edwards grant.b.edwardsYow! I want to dress you at up as TALLULAH BANKHEAD and gmail.comcover you with VASELINE and WHEAT THINS ... -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On 2011-05-05, Roy Smith r...@panix.com wrote: In article ipubhb$e4q$2...@reader1.panix.com, Grant Edwards invalid@invalid.invalid wrote: That's what I was trying to say, but probably not as clearly. The operatore returnas a _value_ that the OP passes _by_value_ to a function. That function then uses the * operator to use that value to access some data. Then, of course, there's references in C++. I think it's fair to call the following call by reference in the sense we're talking about it here. void f(int i) { i = 5; } int i = 42; f(i); If after the call to f(i) the caller sees that i == 5, then that's call by reference. But, we were talking about C. Of course, C++ lets you go off the deep end with abominations like references to pointers. Come to think of it, C++ let's you go off the deep end in so many ways... :) -- Grant Edwards grant.b.edwardsYow! Is this sexual at intercourse yet?? Is it, gmail.comhuh, is it?? -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
On 2011-05-05, Neil Cerutti ne...@norwich.edu wrote: On 2011-05-05, Roy Smith r...@panix.com wrote: Of course, C++ lets you go off the deep end with abominations like references to pointers. Come to think of it, C++ let's you go off the deep end in so many ways... But you can do some really cool stuff in the deep end. Until you get pulled under and drowned by some flailing goof who oughtn't be there. -- Grant Edwards grant.b.edwardsYow! Zippy's brain cells at are straining to bridge gmail.comsynapses ... -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
Grant Edwards wrote: That's what I was trying to say, but probably not as clearly. The operatore returnas a_value_ that the OP passes_by_value_ to a function. That function then uses the * operator to use that value to access some data. I'm gonna try a D'Aprano-style bogus argument for a moment... ... saying that 'C' does not support pass-by-reference because you have to direct the compiler with the '' and '*' characters is a little like saying that Python does not support decorations ! ... ... because you have to direct the interpreter with some @ bogus-decorator-syntax I want Python to support decorations automatically ! ;-) -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
Grant Edwards wrote: No, that's_not_ automatic if you have to do it yourself. It's automatic when it happens without user-intervention. Now I think you're trolling... ... no, I was only kidding... :) -- http://mail.python.org/mailman/listinfo/python-list