SlideShare ist ein Scribd-Unternehmen logo
1 von 13
Assignment #7
CSCE 550
“Parameter passing convention”
Georgiana Tache
gxt6286
Statement of the problem
● A new language AF (Annot-Formal) which extends Mutable
Pairs (chapter 4)
● AF supports:
– Call-by-value
– Call-by-reference
– Call-by-need
● The type of calling is established at the point of procedure
declaration
● New test cases are added to support the differences between the
types of calling
Convention
● The type of calling is distinguished using the following
annotations in front of the procedure argument:
– value
– ref
– lenes - for lazy evaluation
● There is no implicit annotation
● All proc declarations are required to specify the convention
let p = proc (value x) x
in (p 10)
Changes in the lexical spec &
grammar
● Lexical spec supports 3 annotations:
(annot ("lenes") symbol)
(annot ("value") symbol)
(annot ("ref") symbol)
● The grammar for proc is changed to require the type of
parameter passing in the procedure declaration
(expression
("proc" "(" annot identifier ")" expression)
proc-exp)
Abstract Data Types
● ExpVal = Num + Bool + Proc + Reference + Mutpair + Thunk
● Thunk = (Expression, Environment)
● Thunk is used to store the information for evaluating an
expression within an environment. Its evaluation is delayed until
the last moment.
Semantics of the changed expressions
● I keep in the store a global variable mode, which will
save the annotation
● I update its value once the procedure is declared
● I use mode in call-exp, var-exp and apply-procedure
interp.scm
(define mode "")
(define value-of-program
(lambda (pgm)
(initialize-store!)
(set! mode (newref 'unspecified))
(…... ))))))
interp.scm
(proc-exp (annot var body)
(begin
(setref! mode annot)
(proc-val (procedure var body env))
))
Semantics of the changed expressions
interp.scm
(call-exp (rator rand)
(let ((proc (expval->proc (value-of rator env)))
(arg (if (equal? (deref mode) 'value)
(value-of rand env)
(value-of-operand rand env))))
(apply-procedure proc arg)))
In call-exp, the argument of
the function is evaluated with
value-of only if we have call
by value.
In case of call by reference
and call by need, the expression is evaluated with value-of-
operand:
If the operand is a variable then
get its value from the environment.
If it's an expression not bound to a
variable, evaluate it only if we don't
have call by need, and also create
a new reference for it.
(define value-of-operand
(lambda (exp env)
(cases expression exp
(var-exp (var) (apply-env env var))
(else
(newref (if (equal? (deref mode) 'lenes)
(a-thunk exp env)
(value-of exp env)))))))
Semantics of the changed expressions
● A change in apply-procedure
● If call by value – create a new reference, otherwise
use the same reference (which is either bound before
in value-of-operand or bound at the creation of the
variable)
(define apply-procedure
(lambda (proc1 arg)
(cases proc proc1
(procedure (var body saved-env)
(let ((r (if (equal? (deref mode) 'value) (newref arg) arg)))
(let ((new-env (extend-env var r saved-env)))
(value-of body new-env)))))))
Semantics of the changed expressions
Call by need implementation
● A lazy reference evaluation
(define value-of-operand
(lambda (exp env)
(cases expression exp
(var-exp (var) (apply-env env var))
(else
(newref (if (equal? (deref mode) 'lenes)
(a-thunk exp env)
(value-of exp env)))))))
(define-datatype thunk thunk?
(a-thunk
(exp1 expression?)
(env environment?)))
A thunk has an (unevaluated)
expression and an environment
attached.
Semantics of the changed expressions
Call by need implementation
● Modification in var-exp:
interp.scm
(var-exp (var)
(if (not (equal? (deref mode) 'lenes))
(deref (apply-env env var))
; else, lazy evaluation:
(let ((ref1 (apply-env env var)))
(let ((w (deref ref1)))
(if (expval? w) w
(let ((v1 (value-of-thunk w)))
(begin
(setref! ref1 v1)
v1)))))))
If non-lazy evaluation or lazy evaluation of
an expval → get the value of the variable
from the environment
If lazy evaluation of a thunk → evaluate it
using value-of-thunk
data-structures.scm
(define value-of-thunk
(lambda (th)
(cases thunk th
(a-thunk (exp1 saved-env)
(value-of exp1 saved-env)))))
The procedure's argument stays as a thunk until it's
needed in the body and will be evaluated as a var-exp.
Examples of test cases
test1.scm
"newpair (let p = proc(value x)
set x = 4
in let a = 3
in begin
(p a);
a
end, 3)"
test2.scm
"newpair (let p = proc(ref x)
set x = 4
in let a = 3
in begin
(p a);
a
end, 4)"
test4.scm
"newpair (let swap = proc (ref x)
proc (value y)
let temp = x
in begin
set x = y;
set y = temp
end
in let a = 33
in let b = 44
in begin
((swap a) b);
-(a,b)
end , 0)"
Each test file has a tuple:
“newpair (AF-lang-code, expected value)”
Examples of test cases
test6.scm
"newpair (let p = proc(value f) proc(value x)
-(((f f) -(x,1)), -(0,x))
in let newp = proc(lenes n) 25
in (newp ((p p) 5))
, 25)"
Using value or ref instead of lenes → the
program doesn't terminate
> (run-all)
Runs all previous test cases from
tests.scm, where I have modified
the syntax of proc
> (run-all-files)
Runs all additional tests defined in
new files, folder tests
> (run-everything)
Runs both of the above
In top.scm – 2 new functions:
run-file: reading and interpreting one test file
run-all-files: comparing the expected output with
the actual output, for all test files
Questions?

Weitere ähnliche Inhalte

Was ist angesagt?

TestR: generating unit tests for R internals
TestR: generating unit tests for R internalsTestR: generating unit tests for R internals
TestR: generating unit tests for R internalsRoman Tsegelskyi
 
Instruction Combine in LLVM
Instruction Combine in LLVMInstruction Combine in LLVM
Instruction Combine in LLVMWang Hsiangkai
 
STAMP ActiveEon Use Case at Telecom Valley Dec. 2018
STAMP ActiveEon Use Case at Telecom Valley Dec. 2018STAMP ActiveEon Use Case at Telecom Valley Dec. 2018
STAMP ActiveEon Use Case at Telecom Valley Dec. 2018STAMP Project
 
The... Wonderful? World of Lambdas
The... Wonderful? World of LambdasThe... Wonderful? World of Lambdas
The... Wonderful? World of LambdasEsther Lozano
 
Data structure scope of variables
Data structure scope of variablesData structure scope of variables
Data structure scope of variablesSaurav Kumar
 
Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)HamletDRC
 
TDD Boot Camp 東京 for C++ 進行
TDD Boot Camp 東京 for C++ 進行TDD Boot Camp 東京 for C++ 進行
TDD Boot Camp 東京 for C++ 進行Takashi Imagire
 
Effective java item 80 and 81
Effective java   item 80 and 81Effective java   item 80 and 81
Effective java item 80 and 81Isaac Liao
 
Reactive Extensions: classic Observer in .NET
Reactive Extensions: classic Observer in .NETReactive Extensions: classic Observer in .NET
Reactive Extensions: classic Observer in .NETEPAM
 
Mesics lecture 7 iteration and repetitive executions
Mesics lecture 7   iteration and repetitive executionsMesics lecture 7   iteration and repetitive executions
Mesics lecture 7 iteration and repetitive executionseShikshak
 
The Ring programming language version 1.3 book - Part 60 of 88
The Ring programming language version 1.3 book - Part 60 of 88The Ring programming language version 1.3 book - Part 60 of 88
The Ring programming language version 1.3 book - Part 60 of 88Mahmoud Samir Fayed
 
Example First / A Sane Test-Driven Approach to Programming
Example First / A Sane Test-Driven Approach to ProgrammingExample First / A Sane Test-Driven Approach to Programming
Example First / A Sane Test-Driven Approach to ProgrammingJonathan Acker
 
Introduction to RxJS
Introduction to RxJSIntroduction to RxJS
Introduction to RxJSBrainhub
 

Was ist angesagt? (19)

TestR: generating unit tests for R internals
TestR: generating unit tests for R internalsTestR: generating unit tests for R internals
TestR: generating unit tests for R internals
 
Instruction Combine in LLVM
Instruction Combine in LLVMInstruction Combine in LLVM
Instruction Combine in LLVM
 
STAMP ActiveEon Use Case at Telecom Valley Dec. 2018
STAMP ActiveEon Use Case at Telecom Valley Dec. 2018STAMP ActiveEon Use Case at Telecom Valley Dec. 2018
STAMP ActiveEon Use Case at Telecom Valley Dec. 2018
 
The... Wonderful? World of Lambdas
The... Wonderful? World of LambdasThe... Wonderful? World of Lambdas
The... Wonderful? World of Lambdas
 
Intro to Pig UDF
Intro to Pig UDFIntro to Pig UDF
Intro to Pig UDF
 
Pda
PdaPda
Pda
 
LISP:Loops In Lisp
LISP:Loops In LispLISP:Loops In Lisp
LISP:Loops In Lisp
 
Data structure scope of variables
Data structure scope of variablesData structure scope of variables
Data structure scope of variables
 
Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)
 
TDD Boot Camp 東京 for C++ 進行
TDD Boot Camp 東京 for C++ 進行TDD Boot Camp 東京 for C++ 進行
TDD Boot Camp 東京 for C++ 進行
 
Effective java item 80 and 81
Effective java   item 80 and 81Effective java   item 80 and 81
Effective java item 80 and 81
 
Reactive Extensions: classic Observer in .NET
Reactive Extensions: classic Observer in .NETReactive Extensions: classic Observer in .NET
Reactive Extensions: classic Observer in .NET
 
Mesics lecture 7 iteration and repetitive executions
Mesics lecture 7   iteration and repetitive executionsMesics lecture 7   iteration and repetitive executions
Mesics lecture 7 iteration and repetitive executions
 
[ASM]Lab8
[ASM]Lab8[ASM]Lab8
[ASM]Lab8
 
The Ring programming language version 1.3 book - Part 60 of 88
The Ring programming language version 1.3 book - Part 60 of 88The Ring programming language version 1.3 book - Part 60 of 88
The Ring programming language version 1.3 book - Part 60 of 88
 
Example First / A Sane Test-Driven Approach to Programming
Example First / A Sane Test-Driven Approach to ProgrammingExample First / A Sane Test-Driven Approach to Programming
Example First / A Sane Test-Driven Approach to Programming
 
Python testing
Python  testingPython  testing
Python testing
 
Introduction to RxJS
Introduction to RxJSIntroduction to RxJS
Introduction to RxJS
 
[ASM]Lab6
[ASM]Lab6[ASM]Lab6
[ASM]Lab6
 

Andere mochten auch

第三代公路監理資訊系統建置概述
第三代公路監理資訊系統建置概述 第三代公路監理資訊系統建置概述
第三代公路監理資訊系統建置概述 Dylan Chiang, PMP, CISSP
 
Resume (1)
Resume (1)Resume (1)
Resume (1)Sujith S
 
いつ,イデオロギーは「活性化」するのか?
いつ,イデオロギーは「活性化」するのか?いつ,イデオロギーは「活性化」するのか?
いつ,イデオロギーは「活性化」するのか?Masaki Hata
 
政治関心の測定尺度に関する再検討
政治関心の測定尺度に関する再検討政治関心の測定尺度に関する再検討
政治関心の測定尺度に関する再検討Masaki Hata
 
集団的自衛権はいかにして容認されるか?
集団的自衛権はいかにして容認されるか?集団的自衛権はいかにして容認されるか?
集団的自衛権はいかにして容認されるか?Masaki Hata
 
Group theory notes
Group theory notesGroup theory notes
Group theory notesmkumaresan
 
Aries N. Aguila new resume
Aries N. Aguila new resumeAries N. Aguila new resume
Aries N. Aguila new resumeAries Aguila
 
DPS eXplorer: a tool for transparency on public expenditure
DPS eXplorer: a tool for transparency on public expenditureDPS eXplorer: a tool for transparency on public expenditure
DPS eXplorer: a tool for transparency on public expenditurecarloamati
 

Andere mochten auch (13)

第三代公路監理資訊系統建置概述
第三代公路監理資訊系統建置概述 第三代公路監理資訊系統建置概述
第三代公路監理資訊系統建置概述
 
Resume (1)
Resume (1)Resume (1)
Resume (1)
 
いつ,イデオロギーは「活性化」するのか?
いつ,イデオロギーは「活性化」するのか?いつ,イデオロギーは「活性化」するのか?
いつ,イデオロギーは「活性化」するのか?
 
政治関心の測定尺度に関する再検討
政治関心の測定尺度に関する再検討政治関心の測定尺度に関する再検討
政治関心の測定尺度に関する再検討
 
distro baju
distro bajudistro baju
distro baju
 
集団的自衛権はいかにして容認されるか?
集団的自衛権はいかにして容認されるか?集団的自衛権はいかにして容認されるか?
集団的自衛権はいかにして容認されるか?
 
New text document
New text documentNew text document
New text document
 
NSC Solutions
NSC Solutions NSC Solutions
NSC Solutions
 
Group theory notes
Group theory notesGroup theory notes
Group theory notes
 
Aries N. Aguila new resume
Aries N. Aguila new resumeAries N. Aguila new resume
Aries N. Aguila new resume
 
Senior year
Senior yearSenior year
Senior year
 
pengantar anatomi
pengantar anatomipengantar anatomi
pengantar anatomi
 
DPS eXplorer: a tool for transparency on public expenditure
DPS eXplorer: a tool for transparency on public expenditureDPS eXplorer: a tool for transparency on public expenditure
DPS eXplorer: a tool for transparency on public expenditure
 

Ähnlich wie Parameter passing

Knolx Session : Built-In Control Structures in Scala
Knolx Session : Built-In Control Structures in ScalaKnolx Session : Built-In Control Structures in Scala
Knolx Session : Built-In Control Structures in ScalaAyush Mishra
 
Functional programming ii
Functional programming iiFunctional programming ii
Functional programming iiPrashant Kalkar
 
Real Time Big Data Management
Real Time Big Data ManagementReal Time Big Data Management
Real Time Big Data ManagementAlbert Bifet
 
CL metaprogramming
CL metaprogrammingCL metaprogramming
CL metaprogrammingdudarev
 
Parsers Combinators in Scala, Ilya @lambdamix Kliuchnikov
Parsers Combinators in Scala, Ilya @lambdamix KliuchnikovParsers Combinators in Scala, Ilya @lambdamix Kliuchnikov
Parsers Combinators in Scala, Ilya @lambdamix KliuchnikovVasil Remeniuk
 
Lisp Macros in 20 Minutes (Featuring Clojure)
Lisp Macros in 20 Minutes (Featuring Clojure)Lisp Macros in 20 Minutes (Featuring Clojure)
Lisp Macros in 20 Minutes (Featuring Clojure)Phil Calçado
 
Introduction to R
Introduction to RIntroduction to R
Introduction to Ragnonchik
 
TI1220 Lecture 9: Parsing & interpretation
TI1220 Lecture 9: Parsing & interpretationTI1220 Lecture 9: Parsing & interpretation
TI1220 Lecture 9: Parsing & interpretationEelco Visser
 
Loops and functions in r
Loops and functions in rLoops and functions in r
Loops and functions in rmanikanta361
 
Meta-objective Lisp @名古屋 Reject 会議
Meta-objective Lisp @名古屋 Reject 会議Meta-objective Lisp @名古屋 Reject 会議
Meta-objective Lisp @名古屋 Reject 会議dico_leque
 
awkbash quick ref for Red hat Linux admin
awkbash quick ref for Red hat Linux adminawkbash quick ref for Red hat Linux admin
awkbash quick ref for Red hat Linux adminZoumanaDiomande1
 
shellScriptAlt.pptx
shellScriptAlt.pptxshellScriptAlt.pptx
shellScriptAlt.pptxNiladriDey18
 
GUL UC3M - Introduction to functional programming
GUL UC3M - Introduction to functional programmingGUL UC3M - Introduction to functional programming
GUL UC3M - Introduction to functional programmingDavid Muñoz Díaz
 
lisps - A Lisp Interpreter written in Postscript
lisps - A Lisp Interpreter written in Postscriptlisps - A Lisp Interpreter written in Postscript
lisps - A Lisp Interpreter written in PostscriptGabriel Grill
 
ANSI C REFERENCE CARD
ANSI C REFERENCE CARDANSI C REFERENCE CARD
ANSI C REFERENCE CARDTia Ricci
 

Ähnlich wie Parameter passing (20)

Knolx Session : Built-In Control Structures in Scala
Knolx Session : Built-In Control Structures in ScalaKnolx Session : Built-In Control Structures in Scala
Knolx Session : Built-In Control Structures in Scala
 
Ch2
Ch2Ch2
Ch2
 
Functional programming ii
Functional programming iiFunctional programming ii
Functional programming ii
 
Ch2 (1).ppt
Ch2 (1).pptCh2 (1).ppt
Ch2 (1).ppt
 
Meet scala
Meet scalaMeet scala
Meet scala
 
Python to scala
Python to scalaPython to scala
Python to scala
 
Real Time Big Data Management
Real Time Big Data ManagementReal Time Big Data Management
Real Time Big Data Management
 
CL metaprogramming
CL metaprogrammingCL metaprogramming
CL metaprogramming
 
Scala basic
Scala basicScala basic
Scala basic
 
Parsers Combinators in Scala, Ilya @lambdamix Kliuchnikov
Parsers Combinators in Scala, Ilya @lambdamix KliuchnikovParsers Combinators in Scala, Ilya @lambdamix Kliuchnikov
Parsers Combinators in Scala, Ilya @lambdamix Kliuchnikov
 
Lisp Macros in 20 Minutes (Featuring Clojure)
Lisp Macros in 20 Minutes (Featuring Clojure)Lisp Macros in 20 Minutes (Featuring Clojure)
Lisp Macros in 20 Minutes (Featuring Clojure)
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 
TI1220 Lecture 9: Parsing & interpretation
TI1220 Lecture 9: Parsing & interpretationTI1220 Lecture 9: Parsing & interpretation
TI1220 Lecture 9: Parsing & interpretation
 
Loops and functions in r
Loops and functions in rLoops and functions in r
Loops and functions in r
 
Meta-objective Lisp @名古屋 Reject 会議
Meta-objective Lisp @名古屋 Reject 会議Meta-objective Lisp @名古屋 Reject 会議
Meta-objective Lisp @名古屋 Reject 会議
 
awkbash quick ref for Red hat Linux admin
awkbash quick ref for Red hat Linux adminawkbash quick ref for Red hat Linux admin
awkbash quick ref for Red hat Linux admin
 
shellScriptAlt.pptx
shellScriptAlt.pptxshellScriptAlt.pptx
shellScriptAlt.pptx
 
GUL UC3M - Introduction to functional programming
GUL UC3M - Introduction to functional programmingGUL UC3M - Introduction to functional programming
GUL UC3M - Introduction to functional programming
 
lisps - A Lisp Interpreter written in Postscript
lisps - A Lisp Interpreter written in Postscriptlisps - A Lisp Interpreter written in Postscript
lisps - A Lisp Interpreter written in Postscript
 
ANSI C REFERENCE CARD
ANSI C REFERENCE CARDANSI C REFERENCE CARD
ANSI C REFERENCE CARD
 

Kürzlich hochgeladen

Bhiwandi Bhiwandi ❤CALL GIRL 7870993772 ❤CALL GIRLS ESCORT SERVICE In Bhiwan...
Bhiwandi Bhiwandi ❤CALL GIRL 7870993772 ❤CALL GIRLS  ESCORT SERVICE In Bhiwan...Bhiwandi Bhiwandi ❤CALL GIRL 7870993772 ❤CALL GIRLS  ESCORT SERVICE In Bhiwan...
Bhiwandi Bhiwandi ❤CALL GIRL 7870993772 ❤CALL GIRLS ESCORT SERVICE In Bhiwan...Monika Rani
 
CURRENT SCENARIO OF POULTRY PRODUCTION IN INDIA
CURRENT SCENARIO OF POULTRY PRODUCTION IN INDIACURRENT SCENARIO OF POULTRY PRODUCTION IN INDIA
CURRENT SCENARIO OF POULTRY PRODUCTION IN INDIADr. TATHAGAT KHOBRAGADE
 
Molecular markers- RFLP, RAPD, AFLP, SNP etc.
Molecular markers- RFLP, RAPD, AFLP, SNP etc.Molecular markers- RFLP, RAPD, AFLP, SNP etc.
Molecular markers- RFLP, RAPD, AFLP, SNP etc.Silpa
 
Role of AI in seed science Predictive modelling and Beyond.pptx
Role of AI in seed science  Predictive modelling and  Beyond.pptxRole of AI in seed science  Predictive modelling and  Beyond.pptx
Role of AI in seed science Predictive modelling and Beyond.pptxArvind Kumar
 
PSYCHOSOCIAL NEEDS. in nursing II sem pptx
PSYCHOSOCIAL NEEDS. in nursing II sem pptxPSYCHOSOCIAL NEEDS. in nursing II sem pptx
PSYCHOSOCIAL NEEDS. in nursing II sem pptxSuji236384
 
FAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
FAIRSpectra - Enabling the FAIRification of Spectroscopy and SpectrometryFAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
FAIRSpectra - Enabling the FAIRification of Spectroscopy and SpectrometryAlex Henderson
 
300003-World Science Day For Peace And Development.pptx
300003-World Science Day For Peace And Development.pptx300003-World Science Day For Peace And Development.pptx
300003-World Science Day For Peace And Development.pptxryanrooker
 
Genetics and epigenetics of ADHD and comorbid conditions
Genetics and epigenetics of ADHD and comorbid conditionsGenetics and epigenetics of ADHD and comorbid conditions
Genetics and epigenetics of ADHD and comorbid conditionsbassianu17
 
Digital Dentistry.Digital Dentistryvv.pptx
Digital Dentistry.Digital Dentistryvv.pptxDigital Dentistry.Digital Dentistryvv.pptx
Digital Dentistry.Digital Dentistryvv.pptxMohamedFarag457087
 
The Mariana Trench remarkable geological features on Earth.pptx
The Mariana Trench remarkable geological features on Earth.pptxThe Mariana Trench remarkable geological features on Earth.pptx
The Mariana Trench remarkable geological features on Earth.pptxseri bangash
 
Zoology 5th semester notes( Sumit_yadav).pdf
Zoology 5th semester notes( Sumit_yadav).pdfZoology 5th semester notes( Sumit_yadav).pdf
Zoology 5th semester notes( Sumit_yadav).pdfSumit Kumar yadav
 
Factory Acceptance Test( FAT).pptx .
Factory Acceptance Test( FAT).pptx       .Factory Acceptance Test( FAT).pptx       .
Factory Acceptance Test( FAT).pptx .Poonam Aher Patil
 
module for grade 9 for distance learning
module for grade 9 for distance learningmodule for grade 9 for distance learning
module for grade 9 for distance learninglevieagacer
 
Genome sequencing,shotgun sequencing.pptx
Genome sequencing,shotgun sequencing.pptxGenome sequencing,shotgun sequencing.pptx
Genome sequencing,shotgun sequencing.pptxSilpa
 
Porella : features, morphology, anatomy, reproduction etc.
Porella : features, morphology, anatomy, reproduction etc.Porella : features, morphology, anatomy, reproduction etc.
Porella : features, morphology, anatomy, reproduction etc.Silpa
 
Atp synthase , Atp synthase complex 1 to 4.
Atp synthase , Atp synthase complex 1 to 4.Atp synthase , Atp synthase complex 1 to 4.
Atp synthase , Atp synthase complex 1 to 4.Silpa
 
Thyroid Physiology_Dr.E. Muralinath_ Associate Professor
Thyroid Physiology_Dr.E. Muralinath_ Associate ProfessorThyroid Physiology_Dr.E. Muralinath_ Associate Professor
Thyroid Physiology_Dr.E. Muralinath_ Associate Professormuralinath2
 
POGONATUM : morphology, anatomy, reproduction etc.
POGONATUM : morphology, anatomy, reproduction etc.POGONATUM : morphology, anatomy, reproduction etc.
POGONATUM : morphology, anatomy, reproduction etc.Silpa
 
Human genetics..........................pptx
Human genetics..........................pptxHuman genetics..........................pptx
Human genetics..........................pptxSilpa
 
CYTOGENETIC MAP................ ppt.pptx
CYTOGENETIC MAP................ ppt.pptxCYTOGENETIC MAP................ ppt.pptx
CYTOGENETIC MAP................ ppt.pptxSilpa
 

Kürzlich hochgeladen (20)

Bhiwandi Bhiwandi ❤CALL GIRL 7870993772 ❤CALL GIRLS ESCORT SERVICE In Bhiwan...
Bhiwandi Bhiwandi ❤CALL GIRL 7870993772 ❤CALL GIRLS  ESCORT SERVICE In Bhiwan...Bhiwandi Bhiwandi ❤CALL GIRL 7870993772 ❤CALL GIRLS  ESCORT SERVICE In Bhiwan...
Bhiwandi Bhiwandi ❤CALL GIRL 7870993772 ❤CALL GIRLS ESCORT SERVICE In Bhiwan...
 
CURRENT SCENARIO OF POULTRY PRODUCTION IN INDIA
CURRENT SCENARIO OF POULTRY PRODUCTION IN INDIACURRENT SCENARIO OF POULTRY PRODUCTION IN INDIA
CURRENT SCENARIO OF POULTRY PRODUCTION IN INDIA
 
Molecular markers- RFLP, RAPD, AFLP, SNP etc.
Molecular markers- RFLP, RAPD, AFLP, SNP etc.Molecular markers- RFLP, RAPD, AFLP, SNP etc.
Molecular markers- RFLP, RAPD, AFLP, SNP etc.
 
Role of AI in seed science Predictive modelling and Beyond.pptx
Role of AI in seed science  Predictive modelling and  Beyond.pptxRole of AI in seed science  Predictive modelling and  Beyond.pptx
Role of AI in seed science Predictive modelling and Beyond.pptx
 
PSYCHOSOCIAL NEEDS. in nursing II sem pptx
PSYCHOSOCIAL NEEDS. in nursing II sem pptxPSYCHOSOCIAL NEEDS. in nursing II sem pptx
PSYCHOSOCIAL NEEDS. in nursing II sem pptx
 
FAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
FAIRSpectra - Enabling the FAIRification of Spectroscopy and SpectrometryFAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
FAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
 
300003-World Science Day For Peace And Development.pptx
300003-World Science Day For Peace And Development.pptx300003-World Science Day For Peace And Development.pptx
300003-World Science Day For Peace And Development.pptx
 
Genetics and epigenetics of ADHD and comorbid conditions
Genetics and epigenetics of ADHD and comorbid conditionsGenetics and epigenetics of ADHD and comorbid conditions
Genetics and epigenetics of ADHD and comorbid conditions
 
Digital Dentistry.Digital Dentistryvv.pptx
Digital Dentistry.Digital Dentistryvv.pptxDigital Dentistry.Digital Dentistryvv.pptx
Digital Dentistry.Digital Dentistryvv.pptx
 
The Mariana Trench remarkable geological features on Earth.pptx
The Mariana Trench remarkable geological features on Earth.pptxThe Mariana Trench remarkable geological features on Earth.pptx
The Mariana Trench remarkable geological features on Earth.pptx
 
Zoology 5th semester notes( Sumit_yadav).pdf
Zoology 5th semester notes( Sumit_yadav).pdfZoology 5th semester notes( Sumit_yadav).pdf
Zoology 5th semester notes( Sumit_yadav).pdf
 
Factory Acceptance Test( FAT).pptx .
Factory Acceptance Test( FAT).pptx       .Factory Acceptance Test( FAT).pptx       .
Factory Acceptance Test( FAT).pptx .
 
module for grade 9 for distance learning
module for grade 9 for distance learningmodule for grade 9 for distance learning
module for grade 9 for distance learning
 
Genome sequencing,shotgun sequencing.pptx
Genome sequencing,shotgun sequencing.pptxGenome sequencing,shotgun sequencing.pptx
Genome sequencing,shotgun sequencing.pptx
 
Porella : features, morphology, anatomy, reproduction etc.
Porella : features, morphology, anatomy, reproduction etc.Porella : features, morphology, anatomy, reproduction etc.
Porella : features, morphology, anatomy, reproduction etc.
 
Atp synthase , Atp synthase complex 1 to 4.
Atp synthase , Atp synthase complex 1 to 4.Atp synthase , Atp synthase complex 1 to 4.
Atp synthase , Atp synthase complex 1 to 4.
 
Thyroid Physiology_Dr.E. Muralinath_ Associate Professor
Thyroid Physiology_Dr.E. Muralinath_ Associate ProfessorThyroid Physiology_Dr.E. Muralinath_ Associate Professor
Thyroid Physiology_Dr.E. Muralinath_ Associate Professor
 
POGONATUM : morphology, anatomy, reproduction etc.
POGONATUM : morphology, anatomy, reproduction etc.POGONATUM : morphology, anatomy, reproduction etc.
POGONATUM : morphology, anatomy, reproduction etc.
 
Human genetics..........................pptx
Human genetics..........................pptxHuman genetics..........................pptx
Human genetics..........................pptx
 
CYTOGENETIC MAP................ ppt.pptx
CYTOGENETIC MAP................ ppt.pptxCYTOGENETIC MAP................ ppt.pptx
CYTOGENETIC MAP................ ppt.pptx
 

Parameter passing

  • 1. Assignment #7 CSCE 550 “Parameter passing convention” Georgiana Tache gxt6286
  • 2. Statement of the problem ● A new language AF (Annot-Formal) which extends Mutable Pairs (chapter 4) ● AF supports: – Call-by-value – Call-by-reference – Call-by-need ● The type of calling is established at the point of procedure declaration ● New test cases are added to support the differences between the types of calling
  • 3. Convention ● The type of calling is distinguished using the following annotations in front of the procedure argument: – value – ref – lenes - for lazy evaluation ● There is no implicit annotation ● All proc declarations are required to specify the convention let p = proc (value x) x in (p 10)
  • 4. Changes in the lexical spec & grammar ● Lexical spec supports 3 annotations: (annot ("lenes") symbol) (annot ("value") symbol) (annot ("ref") symbol) ● The grammar for proc is changed to require the type of parameter passing in the procedure declaration (expression ("proc" "(" annot identifier ")" expression) proc-exp)
  • 5. Abstract Data Types ● ExpVal = Num + Bool + Proc + Reference + Mutpair + Thunk ● Thunk = (Expression, Environment) ● Thunk is used to store the information for evaluating an expression within an environment. Its evaluation is delayed until the last moment.
  • 6. Semantics of the changed expressions ● I keep in the store a global variable mode, which will save the annotation ● I update its value once the procedure is declared ● I use mode in call-exp, var-exp and apply-procedure interp.scm (define mode "") (define value-of-program (lambda (pgm) (initialize-store!) (set! mode (newref 'unspecified)) (…... )))))) interp.scm (proc-exp (annot var body) (begin (setref! mode annot) (proc-val (procedure var body env)) ))
  • 7. Semantics of the changed expressions interp.scm (call-exp (rator rand) (let ((proc (expval->proc (value-of rator env))) (arg (if (equal? (deref mode) 'value) (value-of rand env) (value-of-operand rand env)))) (apply-procedure proc arg))) In call-exp, the argument of the function is evaluated with value-of only if we have call by value. In case of call by reference and call by need, the expression is evaluated with value-of- operand: If the operand is a variable then get its value from the environment. If it's an expression not bound to a variable, evaluate it only if we don't have call by need, and also create a new reference for it. (define value-of-operand (lambda (exp env) (cases expression exp (var-exp (var) (apply-env env var)) (else (newref (if (equal? (deref mode) 'lenes) (a-thunk exp env) (value-of exp env)))))))
  • 8. Semantics of the changed expressions ● A change in apply-procedure ● If call by value – create a new reference, otherwise use the same reference (which is either bound before in value-of-operand or bound at the creation of the variable) (define apply-procedure (lambda (proc1 arg) (cases proc proc1 (procedure (var body saved-env) (let ((r (if (equal? (deref mode) 'value) (newref arg) arg))) (let ((new-env (extend-env var r saved-env))) (value-of body new-env)))))))
  • 9. Semantics of the changed expressions Call by need implementation ● A lazy reference evaluation (define value-of-operand (lambda (exp env) (cases expression exp (var-exp (var) (apply-env env var)) (else (newref (if (equal? (deref mode) 'lenes) (a-thunk exp env) (value-of exp env))))))) (define-datatype thunk thunk? (a-thunk (exp1 expression?) (env environment?))) A thunk has an (unevaluated) expression and an environment attached.
  • 10. Semantics of the changed expressions Call by need implementation ● Modification in var-exp: interp.scm (var-exp (var) (if (not (equal? (deref mode) 'lenes)) (deref (apply-env env var)) ; else, lazy evaluation: (let ((ref1 (apply-env env var))) (let ((w (deref ref1))) (if (expval? w) w (let ((v1 (value-of-thunk w))) (begin (setref! ref1 v1) v1))))))) If non-lazy evaluation or lazy evaluation of an expval → get the value of the variable from the environment If lazy evaluation of a thunk → evaluate it using value-of-thunk data-structures.scm (define value-of-thunk (lambda (th) (cases thunk th (a-thunk (exp1 saved-env) (value-of exp1 saved-env))))) The procedure's argument stays as a thunk until it's needed in the body and will be evaluated as a var-exp.
  • 11. Examples of test cases test1.scm "newpair (let p = proc(value x) set x = 4 in let a = 3 in begin (p a); a end, 3)" test2.scm "newpair (let p = proc(ref x) set x = 4 in let a = 3 in begin (p a); a end, 4)" test4.scm "newpair (let swap = proc (ref x) proc (value y) let temp = x in begin set x = y; set y = temp end in let a = 33 in let b = 44 in begin ((swap a) b); -(a,b) end , 0)" Each test file has a tuple: “newpair (AF-lang-code, expected value)”
  • 12. Examples of test cases test6.scm "newpair (let p = proc(value f) proc(value x) -(((f f) -(x,1)), -(0,x)) in let newp = proc(lenes n) 25 in (newp ((p p) 5)) , 25)" Using value or ref instead of lenes → the program doesn't terminate > (run-all) Runs all previous test cases from tests.scm, where I have modified the syntax of proc > (run-all-files) Runs all additional tests defined in new files, folder tests > (run-everything) Runs both of the above In top.scm – 2 new functions: run-file: reading and interpreting one test file run-all-files: comparing the expected output with the actual output, for all test files