








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Professor: Leavens; Class: Programming Languages I; Subject: Computer Programming; University: University of Central Florida; Term: Fall 2008;
Typology: Assignments
1 / 14
This page cannot be seen from the preview
Don't miss anything!









Message Passing Semantics and Expressiveness
% $Id: PortAsCellTest.oz,v 1.1 2008/11/14 21:51:26 leavens Exp leavens $ \insert ’PortAsCell.oz’ \insert ’TestingNoStop.oz’
{StartTesting ’MyNewPort’} % Simulating basic semantics of NewPort and Send declare Strm Port in Port = {MyNewPort Strm} {StartTesting ’MySend’} {MySend Port 3} {MySend Port 4} % Must use List.take, otherwise Test suspends... {Test {List.take Strm 2} ’==’ [3 4]} {MySend Port 5} {MySend Port 6} {Test {List.take Strm 4} ’==’ [3 4 5 6]}
{StartTesting ’MyNewPort second part’} declare S2 P2 U1 U2 in P2 = {MyNewPort S2} {StartTesting ’MySend second part’} {MySend P2 7} {MySend P2 unit } {MySend P2 true } {MySend P2 U1} {MySend P2 hmmm(x:U2)} U1 = 4020 {Test {List.take S2 5} ’==’ [7 unit true 4020 hmmm(x:U2)]} {Test {List.take Strm 4} ’==’ [3 4 5 6]}
Message Passing Programming
\insert ’Gauge.oz’ \insert ’TestingNoStop.oz’ declare MyGauge = {NewGauge} {Test local R in {Send MyGauge fetch(R)} R end ’==’ 0} {Send MyGauge up} {Test {Send MyGauge fetch($)} ’==’ 1} {Send MyGauge up} {Test {Send MyGauge fetch($)} ’==’ 2} {Send MyGauge down} {Test {Send MyGauge fetch($)} ’==’ 1} {Send MyGauge up} {Send MyGauge up} {Test {Send MyGauge fetch($)} ’==’ 3}
MyGauge2 = {NewGauge} {Test {Send MyGauge2 fetch($)} ’==’ 0} {Send MyGauge2 down} {Test {Send MyGauge2 fetch($)} ’==’ ~1} {Send MyGauge2 down} {Test {Send MyGauge2 fetch($)} ’==’ ~2} for I in 1..12 do {Send MyGauge2 up} end {Test {Send MyGauge2 fetch($)} ’==’ 10}
\insert ’Auctioneer.oz’ \insert ’TestingNoStop.oz’ declare MyAer = {NewAuctioneer} local Status1 Status2 Status3 Status4 in {Send MyAer bid(8 Status1)} {Send MyAer bid(17 Status2)} {Send MyAer bid(27 Status3)} {Send MyAer bid(24 Status4)} {Send MyAer stop} {Test Status1 ’==’ false } {Test Status2 ’==’ false } {Test Status3 ’==’ true } {Test Status4 ’==’ false } end
MyAer2 = {NewAuctioneer} local Status1 Status2 Status3 Status Status5 Status6 Status in {Send MyAer2 bid(100 Status1)} {Send MyAer2 bid(15 Status2)} {Send MyAer2 bid(99 Status3)} {Send MyAer2 bid(99 Status4)} {Send MyAer2 bid(100 Status5)} {Send MyAer2 bid(100 Status6)} {Send MyAer2 bid(100 Status7)} {Send MyAer2 stop} % first of the highest bids wins {Test Status1 ’==’ true } {Test Status2 ’==’ false } {Test Status3 ’==’ false } {Test Status4 ’==’ false } {Test Status5 ’==’ false } {Test Status6 ’==’ false } {Test Status7 ’==’ false } end
% Stopping with no bids MyAer3 = {NewAuctioneer} {Send MyAer3 stop} % Bidding after an auction is over
\insert ’Mailbox.oz’ \insert ’TestingNoStop.oz’ declare %% conditions for testing (guards), used only for testing purposes fun {Else X} true end fun {Equals Val} fun {$ X} X == Val end end fun {GreaterThan Val} fun {$ X} X > Val end end fun {LessThan Val} fun {$ X} X < Val end end fun {And C1 C2} fun {$ X} {C1 X} andthen {C2 X} end end fun {Or C1 C2} fun {$ X} {C1 X} orelse {C2 X} end end fun {Negate C} fun {$ X} {Not {C X}} end end %% bodies for when guards are true, used only for testing purposes fun {Id X} X end fun {Add Y} fun {$ X} X+Y end end %% Bodies for timeouts, %% note that this is a zero-argument procedure, contrary to the book! fun {Timedout} timedout end
{StartTesting ’Mailbox’} MB={Mailbox.new} {StartTesting ’send’} {Mailbox.send MB 4020} {StartTesting ’receive’} {Test {Mailbox.receive MB [Else#Id] infinity} ’==’ 4020}
{StartTesting ’send and receive of unbound’} {Mailbox.send MB _} {Test {Not {IsDet {Mailbox.receive MB [Else#Id] infinity}}} ’==’ true }
{StartTesting ’Multiple sends and receives’} {Mailbox.send MB 340} {Mailbox.send MB 99} {Test {Mailbox.receive MB [Else#Id] infinity} ’==’ 340} {Test {Mailbox.receive MB [Else#Id] infinity} ’==’ 99}
{StartTesting ’Receive based on guards’} {Mailbox.send MB 11} {Mailbox.send MB 340} {Mailbox.send MB 99} {Mailbox.send MB 33} {Test {Mailbox.receive MB [{Equals 99}#Id] infinity} ’==’ 99} {Test {Mailbox.receive MB [Else#Id] infinity} ’==’ 11} {Test {Mailbox.receive MB [{Equals 33}#Id] infinity} ’==’ 33} {Test {Mailbox.receive MB [Else#Id] infinity} ’==’ 340}
Comparisons Among Models
Extra Credit Problems
References