<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.3314" name=GENERATOR></HEAD>
<BODY>
<DIV><FONT face=Arial size=2><SPAN class=250130610-17082008>I am using Python as
a test language and wondering how best to represent what is shown below in
TTCN-3 </SPAN></FONT></DIV>
<DIV><SPAN class=250130610-17082008><FONT face=Arial size=2>TTCN-3, a testing
domain specific language has a construct that looks like below Its trying
to send a request and define 3 alternative outcomes/events.</FONT></SPAN></DIV>
<DIV><SPAN class=250130610-17082008><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=250130610-17082008><FONT face=Arial size=2>web_port.send("<A
href="http://www.googe.com/">http://www.googe.com/</A>")</FONT></SPAN></DIV>
<DIV><SPAN class=250130610-17082008></SPAN><FONT face=Arial size=2><SPAN
class=250130610-17082008>resonseTimer.start(300)</SPAN></FONT></DIV>
<DIV><SPAN class=250130610-17082008><FONT face=Arial size=2>alt
{</FONT></SPAN></DIV>
<DIV><SPAN class=250130610-17082008> <FONT face=Arial
size=2>[] web_port.receive("something") {</FONT></SPAN></DIV>
<DIV><SPAN class=250130610-17082008>
<FONT face=Arial size=2>responseTimer.stop;</FONT></SPAN></DIV>
<DIV><SPAN class=250130610-17082008>
<FONT face=Arial size=2>setverdict(pass);</FONT></SPAN></DIV>
<DIV><SPAN class=250130610-17082008> <FONT face=Arial
size=2>}</FONT></SPAN></DIV>
<DIV><SPAN class=250130610-17082008>
<DIV><SPAN class=250130610-17082008> <FONT face=Arial
size=2>[] web_port.receive("somethingelse") {</FONT></SPAN></DIV>
<DIV><SPAN class=250130610-17082008>
<FONT face=Arial size=2>responseTimer.stop;</FONT></SPAN></DIV>
<DIV><SPAN class=250130610-17082008>
<FONT face=Arial size=2>setverdict(fail);</FONT></SPAN></DIV>
<DIV><SPAN class=250130610-17082008> <FONT face=Arial
size=2>}</FONT></SPAN></DIV>
<DIV><SPAN class=250130610-17082008>
<DIV><SPAN class=250130610-17082008>
<DIV><SPAN class=250130610-17082008> <FONT face=Arial
size=2>[] responseTimer.timeout {</FONT></SPAN></DIV>
<DIV><SPAN class=250130610-17082008>
<FONT face=Arial size=2>setverdict(fail);</FONT></SPAN></DIV>
<DIV><SPAN class=250130610-17082008> <FONT face=Arial
size=2>}</FONT></SPAN></DIV>
<DIV><SPAN class=250130610-17082008><FONT face=Arial
size=2>}</FONT></SPAN></DIV>
<DIV><SPAN class=250130610-17082008><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=250130610-17082008><FONT face=Arial size=2>I am trying to do
something similar with python and find myself in a fix as to how to code it
clean. </FONT></SPAN></DIV>
<DIV><SPAN class=250130610-17082008><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=250130610-17082008><FONT face=Arial size=2>I can't
do it with</FONT></SPAN></DIV>
<DIV><SPAN class=250130610-17082008><FONT face=Arial
size=2> if ...elseif ... elseif ....
else </FONT></SPAN></DIV>
<DIV><SPAN class=250130610-17082008><FONT face=Arial size=2>unless I wrap it in
an event loop.</FONT></SPAN></DIV>
<DIV><SPAN class=250130610-17082008><FONT face=Arial size=2>Since otherwise it
means that each condition function will be executed
once. </FONT> <FONT face=Arial size=2>While what we are looking for is
way to define potential events that can happen and a particular segment of code
to executed for a specific event match</FONT></SPAN></DIV>
<DIV><SPAN class=250130610-17082008><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=250130610-17082008><FONT face=Arial size=2>The closest thing
that I can do is something like this, assuming I implement the
doalternatives method to take a list of function, code pairs. It
would take the list of function-name, parameters list and run it in an event
loop or in separate threads as the need may be to match one of them.
</FONT></SPAN></DIV>
<DIV><SPAN class=250130610-17082008><FONT face=Arial size=2>When one of them
matches it would be expected to run the code block associated with it. Which
would get me the same behaviour.</FONT></SPAN></DIV>
<DIV><SPAN class=250130610-17082008><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=250130610-17082008><FONT face=Arial
size=2>doalternatives(</FONT></SPAN></DIV>
<DIV><SPAN class=250130610-17082008><FONT face=Arial size=2>
[web_port.receive,"something"],</FONT></SPAN></DIV>
<DIV><SPAN
class=250130610-17082008>
<FONT face=Arial size=2>"<SPAN class=250130610-17082008><FONT face=Arial
size=2>responseTimer.stop;</FONT></SPAN>
<DIV><SPAN
class=250130610-17082008>
<FONT face=Arial size=2>setverdict(pass);"</FONT></SPAN></DIV>
<DIV><SPAN class=250130610-17082008>
<DIV><SPAN class=250130610-17082008><FONT face=Arial size=2>
[web_port.receive,"somethingelse"],</FONT></SPAN></DIV>
<DIV><SPAN
class=250130610-17082008>
<FONT face=Arial size=2>"<SPAN class=250130610-17082008><FONT face=Arial
size=2>responseTimer.stop;</FONT></SPAN>
<DIV><SPAN
class=250130610-17082008>
<FONT face=Arial size=2>setverdict(fail);"</FONT></SPAN></DIV>
<DIV><SPAN class=250130610-17082008>
<DIV><SPAN class=250130610-17082008><FONT face=Arial size=2>
[responseTimer.timeout],</FONT></SPAN></DIV>
<DIV><SPAN
class=250130610-17082008>
<FONT face=Arial size=2>"<SPAN class=250130610-17082008><FONT face=Arial
size=2>responseTimer.stop;</FONT></SPAN>
<DIV><SPAN
class=250130610-17082008>
<FONT face=Arial size=2>setverdict(pass);"</FONT></SPAN></DIV>
<DIV><SPAN class=250130610-17082008>}</SPAN></DIV>
<DIV><SPAN class=250130610-17082008></SPAN> </DIV>
<DIV><SPAN class=250130610-17082008>The above looks pretty ok. Except that I
have to define the python code block as a string.</SPAN></DIV>
<DIV><SPAN class=250130610-17082008>It would be nice if there was a python
language construct that would allow me to define a block of python code that can
be passed as a code object into a function.</SPAN></DIV>
<DIV><SPAN class=250130610-17082008></SPAN> </DIV>
<DIV><SPAN class=250130610-17082008>That would serve the above purpose as well
as cases for distributed or parallel programming as well.</SPAN></DIV>
<DIV><SPAN class=250130610-17082008></SPAN> </DIV>
<DIV><SPAN class=250130610-17082008>A construct like</SPAN></DIV>
<DIV><SPAN class=250130610-17082008>invoke doalternatives
with:</SPAN></DIV>
<DIV><SPAN class=250130610-17082008> param
[web_port.receive,"something"]</SPAN></DIV>
<DIV><SPAN class=250130610-17082008> param:</SPAN></DIV>
<DIV><SPAN class=250130610-17082008>
responseTimer.stop()</SPAN></DIV>
<DIV><SPAN class=250130610-17082008>
setverdict(pass)</SPAN></DIV>
<DIV><SPAN class=250130610-17082008>
<DIV><SPAN class=250130610-17082008> param
[web_port.receive,"something else"]</SPAN></DIV>
<DIV><SPAN class=250130610-17082008> param:</SPAN></DIV>
<DIV><SPAN class=250130610-17082008>
responseTimer.stop()</SPAN></DIV>
<DIV><SPAN class=250130610-17082008>
setverdict(fail)</SPAN></DIV></SPAN></DIV>
<DIV><SPAN class=250130610-17082008>
<DIV><SPAN class=250130610-17082008> param
[responseTimer.timeout]</SPAN></DIV>
<DIV><SPAN class=250130610-17082008> param:</SPAN></DIV>
<DIV><SPAN class=250130610-17082008>
responseTimer.stop()</SPAN></DIV>
<DIV><SPAN class=250130610-17082008>
setverdict(pass)</SPAN></DIV>
<DIV><SPAN class=250130610-17082008></SPAN> </DIV>
<DIV><SPAN class=250130610-17082008>I am sure we can do better than what I have
proposed above. But the general idea is to be able to define and pass code
segments as code objects around a function invocation and and pass the code
objects as parameters into the invoked function.</SPAN></DIV>
<DIV><SPAN class=250130610-17082008></SPAN> </DIV>
<DIV><SPAN class=250130610-17082008>What do people think? Is there any existing
construct that I might be missing to achieve the above?</SPAN></DIV>
<DIV><SPAN class=250130610-17082008></SPAN> </DIV>
<DIV><SPAN
class=250130610-17082008>Sarvi</SPAN></DIV></SPAN></DIV></FONT></SPAN></DIV></SPAN></DIV></FONT></SPAN></DIV></SPAN></DIV></FONT></SPAN></DIV></SPAN></DIV></SPAN></DIV></SPAN></DIV></BODY></HTML>