Sophie

Sophie

distrib > Fedora > 14 > x86_64 > by-pkgid > c31bd254217aaa94cdc6327ba697d385 > files > 83

nip2-7.22.2-1.fc14.2.x86_64.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  
  "http://www.w3.org/TR/html4/loose.dtd">  
<html > 
<head><title>Lazy programming</title> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
<meta name="generator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)"> 
<meta name="originator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)"> 
<!-- 3,html --> 
<meta name="src" content="nipguide.tex"> 
<meta name="date" content="2010-06-30 13:34:00"> 
<link rel="stylesheet" type="text/css" href="nipguide.css"> 
</head><body 
>
  <!--l. 855--><div class="crosslinks"><p class="noindent">[<a 
href="nipguidese30.html" >next</a>] [<a 
href="nipguidese28.html" >prev</a>] [<a 
href="nipguidese28.html#tailnipguidese28.html" >prev-tail</a>] [<a 
href="#tailnipguidese29.html">tail</a>] [<a 
href="nipguidech6.html#nipguidese29.html" >up</a>] </p></div>
  <h3 class="sectionHead"><span class="titlemark">6.8    </span> <a 
 id="x40-720006.8"></a>Lazy programming</h3>
<!--l. 856--><p class="noindent" ><a name="nip_label_sec:lazy"></a>
<!--l. 858--><p class="indent" >  <span 
class="pcrr7t-">nip2</span>&#8217;s programming language is <span 
class="ptmri7t-">lazy</span>, that is, it delays
evaluation as long as it possibly can. For example, <span 
class="pcrr7t-">error</span>
is a function which immediately halts execution of your
function and pops up an alert window. So:
                                                 <div class="verbatim" id="verbatim-61">
  12&#x00A0;+&#x00A0;error&#x00A0;"wombat!" 
</div>
<!--l. 864--><p class="nopar" >
<!--l. 866--><p class="noindent" >Has no value: this expression will halt with an error
message. However:
                                                                                       

                                                                                       
  <div class="verbatim" id="verbatim-62">
false&#x00A0;&amp;&amp;&#x00A0;error&#x00A0;"lasagne!"
</div>
<!--l. 871--><p class="nopar" >
<!--l. 873--><p class="noindent" >Will evaluate to <span 
class="pcrr7t-">false</span>, since <span 
class="pcrr7t-">nip2 </span>knows after looking at
the left-hand-side of <span 
class="pcrr7t-">&amp;&amp; </span>that the result must be <span 
class="pcrr7t-">false</span>, and
so does not evaluate the right-hand-side.
                                                 <div class="verbatim" id="verbatim-63">
  [12,&#x00A0;error&#x00A0;"hot&#x00A0;chilli!"]&#x00A0;?&#x00A0;0&#x00A0;==&#x00A0;12 
</div>
<!--l. 880--><p class="nopar" >
<!--l. 882--><p class="noindent" >This also evaluates completely, since the second element of
the list is never used, and therefore never evaluates.
<!--l. 886--><p class="indent" >    Things become more confusing when you start calling
functions, since the arguments to a function call are also
not evaluated until the function needs that value. For
example:
                                                                                       

                                                                                       
  <div class="verbatim" id="verbatim-64">
foldr&#x00A0;(error&#x00A0;"boink!")&#x00A0;2&#x00A0;[]&#x00A0;==&#x00A0;2
</div>
<!--l. 892--><p class="nopar" >
<!--l. 894--><p class="noindent" >Again, this evaluates successfully, since the function is
never used by <span 
class="pcrr7t-">foldr</span>.
                                           
                                                                                       

                                                                                       
  <!--l. 898--><div class="crosslinks"><p class="noindent">[<a 
href="nipguidese30.html" >next</a>] [<a 
href="nipguidese28.html" >prev</a>] [<a 
href="nipguidese28.html#tailnipguidese28.html" >prev-tail</a>] [<a 
href="nipguidese29.html" >front</a>] [<a 
href="nipguidech6.html#nipguidese29.html" >up</a>] </p></div>
<!--l. 898--><p class="indent" >  <a 
 id="tailnipguidese29.html"></a>  
</body></html>