<!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>’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 + error "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 && error "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-">&& </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, error "hot chilli!"] ? 0 == 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 (error "boink!") 2 [] == 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>