At 07:38 AM 7/17/2007, Kent Johnson wrote: >Dick Moores wrote: >>At 04:57 AM 7/17/2007, you wrote: >>>A recent comp.lang.python thread has a good explanation of Python's >>>assignment semantics: >>>http://groups.google.com/group/comp.lang.python/browse_thread/thread/56e7d62bf66a435c/ >>> >>> >> >>Kent, >>Yes, interesting. But could you explain what you mean by >>"assignment semantics"? Semantics: < >>http://dictionary.reference.com/search?q=semantics> >>I have trouble relating semantics to programming. > >Semantics: The study or science of meaning in language. > >In other words, what does it mean to say > a = b >in Python? > >Syntax is like spelling and grammar rules - if you understand >syntax, you can write a program that will compile and run. But >without understanding what the various programming constructs >actually mean, you will have trouble writing a program that does >something useful. > >I think to write correct programs in any language, you must have a >correct mental model of what the program is doing, where by >'correct' I mean a model that is consistent with the actual >behaviour of the program. > >Programmers coming from a background in C and C++ have a mental >model of variables as containers for values. This model works in >those languages, where variables correspond to memory locations and >assignment copies a value from one location to another. It doesn't >work in Python, where variables are names for values and assignment >creates another name for the same value without copying. To write >correct Python programs you have to have a different model for what >variables are and how they behave. We regularly see questions on >this list from people who are confused by assignment because they >are using a faulty model. > >So "what does it mean?" might be interpreted as "what is a useful >model of this operation that allows me to understand and predict its >behaviour?", and "assignment semantics" is a shortcut for saying "a >useful model of assignment that allows me to understand and predict >its behaviour." > >Kent
Thanks very much for your trouble, Kent. A big help. Dick _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor