On Wed, 12 Nov 2008 13:10:10 +1300, greg wrote: > Here is the definition of call-by-value from the "Revised Report on the > Algorithmic Language Algol 60" > <http://www.masswerk.at/algol60/report.htm>:
Why should anyone take the "Revised Report on the Algorithmic Language Algol 60" as the "official" (only?) definition of call-by-value for all languages everywhere? Particularly since in practice, people's *understanding* of such terms have more to do with common practice than formal definitions. You're welcome to tell people that tomatoes are actually berries from the Deadly Nightshade family of plants, rather than vegetables, but if you do so you better follow it up with further explanations. > 4.7.3.1. Value assignment (call by value). All formal parameters quoted > in the value part of the procedure declaration heading are assigned the > values (cf. section 2.8. Values and types) of the corresponding actual > parameters, these assignments being considers as being performed > explicitly before entering the procedure body. The effect is as though > an additional block embracing the procedure body were created in which > these assignments were made to variables local to this fictitious block > with types as given in the corresponding specifications (cf. section > 5.4.5). I notice that you deleted the last sentence of the definition. I quote: "As a consequence, variables called by value are to be considered as nonlocal to the body of the procedure, but local to the fictitious block (cf. section 5.4.3)." And what's the fictitious block? As I understand it, their intention is to say that calling a procedure foo(x) with an actual argument y should be considered the same as: # start a new block (a new scope, in Python terminology) x = y # behave as if we explicitly assigned y to x foo(x) # enter the body of foo with argument x local to the new block What are the consequences of such assignment? Unfortunately, assignment isn't unambiguously defined: "4.2.3. Semantics. Assignment statements serve for assigning the value of an expression to one or several variables or procedure identifiers. Assignment to a procedure identifier may only occur within the body of a procedure defining the value of a function designator (cf. section 5.4.4). The process will in the general case be understood to take place in three steps as follows: 4.2.3.1. Any subscript expression occurring in the left part variables are evaluated in sequence from left to right. 4.2.3.2. The expression of the statement is evaluated. 4.2.3.3. The value of the expression is assigned to all the left part variables, with any subscript expressions having values as evaluated in step 4.2.3.1." In other words, assignment takes three steps: (1) evaluate the subscript expressions on the left part (presumably of the statement); (2) evaluate the expression of the statement (presumably the right hand side, but the document doesn't make that clear); (3) assign the value of the expression. Got that? Assignment means the value is assigned. Glad that's all clear then. So given an assignment of x = y in Algol, it isn't clear from this document whether x and y refer to the same value, or if they merely have the same value by equality. That second case would imply copying. To put it in Python terms, following x = y we know that x == y is true but we don't know whether id(x) == id(y). Can we at least determine what variables and values are? Well, almost... "3.1.3. Semantics. A variable is a designation given to a single value." Okay, a variable is a designation (a name if you prefer) for a value. So what's a value? "2.8. Values and types A value is an ordered set of numbers (special case: a single number), an ordered set of logical values (special case: a single logical value), or a label. Certain of the syntactic units are said to possess values. These values will in general change during the execution of the program The values of expressions and their constituents are defined in section 3. The value of an array identifier is the ordered set of values of the corresponding array of subscripted variables (cf. section 3.1.4.1)." Now we're getting somewhere! Values are sets of numbers or sets of true/ false logical elements. Hmmm... apparently strings aren't values in Algol. Oh well. But one thing is clear: values aren't references. Given the assignment x=1, the value of x is not "a reference to 1" but 1 itself. So the one thing we can unambiguously say is that Algol's assignment model is not the same as Python's assignment model. -- Steven -- http://mail.python.org/mailman/listinfo/python-list