CORNELL CS 611 - Lecture 15 Parameter Passing

Unformatted text preview:

CS611 Lecture 15 Parameter Passing September 21, 2000Scribe: Niranjan Nagarajan and Bo Pang Lecturer: Andrew MyersIn this lecture we shall discuss several different styles of parameter passing and ways of defining the scopeof function definitions. For the purpose of illustration of these ideas we shall use the REC+language whichis basically an extension of the REC language used in Chapter 9 of Winskell. We start off by presenting theOperational and Denotational Semantics of REC+.1REC+languageSyntactic Formsd ::= f1(x1,...,xa1)=e1...fn(x1,...,xan)=ene ::= n | X | e1⊕ e2| ifz e0then e1else e2| let x = e1in e2progr am ::= deOperational Semanticsv ::= n(d, ifz 0 then e1else e2) −→ (d, e1)(d, ifz v then e1else e2) −→ (d, e2) where v =0(d, v1⊕ v2) −→ (d, n3)wheren3= v1⊕ v2(d, let x = v in e) −→ (d, e{v/x})(d, fi(vi...vai)) −→ (d, ei{vj/xjj∈1.. ai})DomainsC[[ e]] ∈ FEnv −→ Env −→ ResultResult = Z⊥Env = Var −→ ZFEnv =(Za1 −→ Result) × ...× (Zan −→ Result)Denotational SemanticsC[[ n]] φρ = nC[[ x]] φρ = ρ(x)C[[ e1⊕ e2]] φρ = C[[ e1]] φρ ⊕⊥C[[ e2]] φρC[[ ifz e0then e1else e2]] φρ = let v = C[[ e0]] φρ . if v =0then C[[ e1]] φρ else C[[ e2]] φρC[[ let x = e1in e2]] φρ = let v = C[[ e1]] φρ . C[[ e2]] φρ[x → v]C[[ fi(e1,...,eai)]]φρ = let v1= C[[ e1]] φρ.(...letvai= C[[ eai]] φρ . πiφ(v1,...,vai) ...)The Operational and Denotational Semantics given here do not address the question of how we get thefunction environments φ. Also in the Denotational Semantics that we have given we define the languageconstructs like let in terms of the corresponding mathematical constructs and the definition seems to besuspiciously circular. In the following section we shall try to address these problems and also demonstratean application of Denotational Semantics.2 Parameter Passing and Function ScopeREC+as we have defined above has call-by-value semantics as we need to β-reduce operands before functionevaluations. Let us explore the semantics of other methods of parameter passing using REC+.Hereisatable of the various kinds of parameter passing modes and function scopes that we shall consider:Param. Passing Function ScopeA CBV 1 Function only in scope in later functions (FORTRAN 77 or earlier)B CBN 2 Function can be recursive but can’t call later functions (C without fwd decls.)C CBD 3 Function can call later functions (letrec in Scheme, Java)1CBV, CBN and CBD stand for call-by-value, call-by-name and call-by-denotation respectively. We shallrefer to the languages that we consider by the alphabet, number pairs indicated by the table, so for e.g. B3is the name for the language that has call-by-name and in which functions can call later functions.We invent a new meaning function D s.t. D[[ d]] gives us the function environment that corresponds tothe meaning of the function declarations d in a particular semantics. We would then distinguish the varioussemantics based on the way in which D is defined. So the meaning of a program [[de]] is given by the meaningof e in the function enviorment D[[ d]] with the initial variable environment being the empty set (since in thebeginning none of the variables are bound to any values.)[[ de]] = C[[ e]] D[[ d]] ∅D[[ d]] = F1,...,Fnwhere the Fiare denotations of the fiin d.3A1andB1A1. The semantics for the A1 language can be expressed by the following additional definitions:Di−1[[ d]] = F1,...,Fi−1Fi= λv ∈ Zai. C[[ ei]] Di−1[[ d]] {xj → πjvj∈1..ai}Here we are defining Fion previous F, and we can inductively build up the Di[[ d]] s u c h t h a t D[[ d]] = Dn[[ d]] .Note that here our definitions make sense even when the result domain is not a pointed domain. This indicatesthat the A1 language does not have divergent computations. The A1 language is not very powerful and infact one cannot even write infinite loops in it. The semantics of A1 can also be expressed by inlining functioncalls in e for the functions in d in sequential order.B1. Since the semantics of call-by-name differs from call-by-value only in the presence of non-terminatingcomputations and since all languages X1 (where X ∈{A, B, C}) lack non-terminating computations, thesemantics of B1 is identical to that of A1.4A2andB2A2. By allowing functions to be recursive we force our definitions of Fito be recursively defined in termsof Di[[ d]]. We therefore need to use fixed points to remove the circularity in the definitions:Fi= fix(λf ∈ Zai −→ Z. λv ∈ Zai. C[[ ei]] F1,...,Fi−1,f{xj → πjvj∈1...ai})Clearly by allowing recursion we open up the possibility of divergent computation in A2. We also note thatfor the A2 language the result domain has to be pointed in order for us to be able to take the fixed pointgiven by the above definition.B2. We need to modify our definition for Env and FEnv to allow for the presence of divergent computationsas arguments to functions.Env = Var −→ Z⊥FEnv =(Z⊥a1 −→ Z⊥) × ...× (Z⊥an −→ Z⊥)In addition we need to make the following changes to our definitions:C[[ x]] φρ = ρ(x)C[[ let x = e1in e2]] φρ = C[[ e2]] ρ[x → C[[ e1]] φρ]φC[[ fi(e1,...,eai)]]φρ = πiφ(C[[ e1]] φρ,...,C[[ eai]] φρ)Suprisingly the denotational semantics for call-by-name is much more compact and simple than the semanticsfor call-by-value. This is because the underlying mathematical language used by us is biased towards lazylanguages.25A3andB3A3. When a function can refer to all the other functions, how do we obtain φ? We will first pretend thatwe already have this function environment φ, and then we could write:Fi= λv ∈ Zai.C[[ ei]] φρ[xj → πjv]But this is a circular definition, sinceφ = F1,...,FnClearly, we have to again take a fixed point!φ = fix λφ.F1(φ),...,Fn(φ)We know that this function is continuous and we need to check if the domain is a pointed cpo, we haveφ ∈ (Za1 −→ Z⊥) × ...× (Zan −→ Z⊥)Since Z⊥is a pointed cpo, so each function domain Zai −→ Z⊥is also a pointed cpo, and the productdomain of all these pointed cpo function domains is still a pointed cpo.Since the function environment is defined in terms of fixed points which in turn are defined by LUB’sof infinite sequences it seems like our function environments would need to be an infinite data structure.However our function environments need to be finite in any


View Full Document

CORNELL CS 611 - Lecture 15 Parameter Passing

Download Lecture 15 Parameter Passing
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 15 Parameter Passing and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 15 Parameter Passing 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?