Problem with assigning variables of type List
Donn Cave
donn at drizzle.com
Tue Aug 20 23:37:32 EDT 2002
More information about the Python-list mailing list
Tue Aug 20 23:37:32 EDT 2002
- Previous message (by thread): Problem with assigning variables of type List
- Next message (by thread): Problem with assigning variables of type List
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Quoth Paul Foley <see at below>: ... | Fine, let's see what FOLDOC has to say, shall we? :- | | CALL-BY-VALUE: | | (CBV) An evaluation strategy where arguments are evaluated before | the function or procedure is entered. Only the values of the | arguments are passed and changes to the arguments within the called | procedure have no effect on the actual arguments as seen by the | caller. See applicative order reduction, call-by-value-result, | strict evaluation, call-by-name, lazy evaluation. | | So: arguments are evaluated before the function or procedure is | entered? Yup, Python does that. Only the values are passed, and | changes to the arguments within the called procedure have no effect on | the actual arguments as seen by the caller? Right again. Python | meets that definition. I guess it's call-by-value (what a surprise!) Python meets that definition only if you understand ``changes to the arguments'' to mean ``assignment to the arguments.'' | CALL-BY-REFERENCE | | An argument passing convention where the address of an argument | variable is passed to a function or procedure, as opposed to where | the value of the argument expression is passed. Execution of the | function or procedure may have side-effects on the actual argument | as seen by the caller. The C language's "&" (address of) and "*" | (dereference) operators allow the programmer to code explicit | call-by-reference. Other languages provide special syntax to declare | reference arguments (e.g. ALGOL 60). See also call-by-name, | call-by-value, call-by-value-result. | | So, the address of the argument variable is passed? Not in Python[1]. | Execution of the function or procedure may have side-effects on the | actual argument as seen by the caller? Not in Python. Python fails | to meet this definition. I guess it's not call-by-reference Yes, you may have side effects in Python, for heavens sake. Pass a list and append to it, or any number of other operations that change state in the object. Just like C. In C or Python, you may assign to the value passed with no side effect to the caller, but if you modify state pointed to, there will be a side effect. C differs in allowing you to overwrite the contents of any object, so the exposure to side effects is more consistent than with Python's limited set of state changing operations, but it's the same in principle and for the same reason - we're calling by reference. More or less. Donn Cave, donn at drizzle.com
- Previous message (by thread): Problem with assigning variables of type List
- Next message (by thread): Problem with assigning variables of type List
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list