about summary refs log blame commit diff stats
path: root/html/071recipe.cc.html
blob: f661b770cdc925a05719f05b063e52be586d2fe1 (plain) (tree)
1
2
3
4
5
6
7
8
9
10



                                                                                          
                                

                                                
                                  

                                                                                         

                       
                                                                                                 
                                                                                            

                                      
                             
                             
                                   
                            

                              
                                  
                                                                           
                               

        





                               

       
                         


                                                                                                                  

                                                                                                                    

                                                              
                                        
                                                                                                                                                
 
                                                                                     






                                                                 


                                                                                                                                                                                                                                                                                                          
 
                                                                                     











                                                                                                                                                                                                                                           




















                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
                                                                                                                                                                                                            
                                                                                                                                                                                                                                     













                                                                                                                                                                                                                                                                                                                                                                                                                                      

                                                                                                                                                                                                                                                                                                    

                                



                                                                                                        
                                        
             

                                                                                                                                                                               

                                                                                                                    
                                                                                                          
 




                                                                                                                                                                                                      


                                                                                                                                                                                                                                                                                                                                                                                                                                     

                                                                         
                                                                                                                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                




                                                                                         
                                                                       
                                            
                                                                                                                                              



                                                                                                                                                                                                                                                                                                                                                     



                                                                                                                                                                                                                                                                                                                                                                                                            
                                                                                                                               









                                                                                                                                                                                                                                                                                                                                                                                                                         
                                        
                                                                                                                                                
 
                                                                                         



                                             

                                                                                                            


                                                                     


                                                                                                                                                                                                                                                                                                        
 
                                                                                         



                                             

                                                                                                                                          



                                                                                                                                                                                                  
                                                                                                                                                                                                                       
                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
                                                                                                                                                                     
                                                                                                                                                                                                                                                                                                                                                                  








                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
                                    


                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        



                                    
                                                                                                                                                                                                  
                                                                                                              

                                                                                                                                                




                                                                                                                                                                                                                                                    
                                                                                                                                                                    

                                                                                                                                                                                                                                                                                                                                                                                                                     
                                                                                                                                          
                                                                                        
                                    
                                                                                                                                                                                                                                                                      
                                  





                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                                                                                    


                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                                           
                                  


                                                                                      
























                                                                                                                                                                                                                                   
 
                                      







                                                                                                                                                                                                                                                                                                                                                            
                                                                                                                                                                                              
                                                                                                                                                                                                                                                  



                                                                                                                                                                                                                                                                                                                                                                                    




                                                                                                            
                                        
                                                                                                                                                      

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
 
                                                                                     



                                             
                                                                                                                                                           


                                                                           

                                                                                                                                                                                                                                                                                                     
 
                                                                                                                                               



                                             
                                                                                                                         
 
                                                                                       


                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 

                                                                                                              



                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                

                                                                                                                

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          



                                                                                                                
 
                                                                            

                                                                                                                                                                                                                                                                                                              
                                                                                                                   
                                                                                                                                                                                                                                                                                                                                                                                           
 
                                                                                           





                                             


                                                                                            
                                       

             
                                        





                                                                            
                                                                                       











                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             


       
                                     
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Mu - 071recipe.cc</title>
<meta name="Generator" content="Vim/7.4">
<meta name="plugin-version" content="vim7.4_v2">
<meta name="syntax" content="cpp">
<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy=">
<meta name="colorscheme" content="minimal">
<style type="text/css">
<!--
pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; }
body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color: #080808; }
* { font-size: 12pt; font-size: 1em; }
.Constant { color: #00a0a0; }
.cSpecial { color: #008000; }
.muRecipe { color: #ff8700; }
.SalientComment { color: #00ffff; }
.Comment { color: #9090ff; }
.Delimiter { color: #800080; }
.Special { color: #c00000; }
.traceContains { color: #008000; }
.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; }
.Identifier { color: #fcb165; }
-->
</style>

<script type='text/javascript'>
<!--

-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="Comment">//: So far we've been calling a fixed recipe in each instruction, but we'd</span>
<span class="Comment">//: also like to make the recipe a variable, pass recipes to &quot;higher-order&quot;</span>
<span class="Comment">//: recipes, return recipes from recipes and so on.</span>
<span class="Comment">//:</span>
<span class="Comment">//: todo: support storing shape-shifting recipes into recipe variables and calling them</span>

<span class="Delimiter">:(scenario call_literal_recipe)</span>
<span class="muRecipe">def</span> main [
  <span class="Constant">1</span>:num<span class="Special"> &lt;- </span>call f<span class="Delimiter">,</span> <span class="Constant">34</span>
]
<span class="muRecipe">def</span> f x:num<span class="muRecipe"> -&gt; </span>y:num [
  local-scope
  load-ingredients
  y<span class="Special"> &lt;- </span>copy x
]
<span class="traceContains">+mem: storing 34 in location 1</span>

<span class="Delimiter">:(scenario call_variable)</span>
<span class="muRecipe">def</span> main [
  <span class="Delimiter">{</span><span class="Constant">1</span>: <span class="Delimiter">(</span>recipe number<span class="muRecipe"> -&gt; </span>number<span class="Delimiter">)}</span><span class="Special"> &lt;- </span>copy f
  <span class="Constant">2</span>:num<span class="Special"> &lt;- </span>call <span class="Delimiter">{</span><span class="Constant">1</span>: <span class="Delimiter">(</span>recipe number<span class="muRecipe"> -&gt; </span>number<span class="Delimiter">)},</span> <span class="Constant">34</span>
]
<span class="muRecipe">def</span> f x:num<span class="muRecipe"> -&gt; </span>y:num [
  local-scope
  load-ingredients
  y<span class="Special"> &lt;- </span>copy x
]
<span class="traceContains">+mem: storing 34 in location 2</span>

<span class="Delimiter">:(before &quot;End Mu Types Initialization&quot;)</span>
put<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">&quot;recipe-literal&quot;</span><span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span>
<span class="Comment">// 'recipe' variables can store recipe-literal</span>
type_ordinal recipe = put<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">&quot;recipe&quot;</span><span class="Delimiter">,</span> Next_type_ordinal++<span class="Delimiter">);</span>
get_or_insert<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> recipe<span class="Delimiter">).</span>name = <span class="Constant">&quot;recipe&quot;</span><span class="Delimiter">;</span>

<span class="Delimiter">:(after &quot;Begin transform_names Ingredient Special-cases(ingredient, inst, caller)&quot;)</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>is_recipe_literal<span class="Delimiter">(</span>ingredient<span class="Delimiter">,</span> caller<span class="Delimiter">))</span> <span class="Delimiter">{</span>
  initialize_recipe_literal<span class="Delimiter">(</span>ingredient<span class="Delimiter">);</span>
  <span class="Identifier">continue</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
<span class="Delimiter">:(after &quot;Begin transform_names Product Special-cases(product, inst, caller)&quot;)</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>is_recipe_literal<span class="Delimiter">(</span>product<span class="Delimiter">,</span> caller<span class="Delimiter">))</span> <span class="Delimiter">{</span>
  initialize_recipe_literal<span class="Delimiter">(</span>product<span class="Delimiter">);</span>
  <span class="Identifier">continue</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
<span class="Delimiter">:(code)</span>
<span class="Normal">bool</span> is_recipe_literal<span class="Delimiter">(</span><span class="Normal">const</span> reagent&amp; x<span class="Delimiter">,</span> <span class="Normal">const</span> recipe&amp; caller<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> x<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>contains_reagent_with_type<span class="Delimiter">(</span>caller<span class="Delimiter">,</span> x<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span>
    raise &lt;&lt; maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;you can't use '&quot;</span> &lt;&lt; x<span class="Delimiter">.</span>name &lt;&lt; <span class="Constant">&quot;' as a recipe literal when it's also a variable</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
    <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
  <span class="Delimiter">}</span>
  <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
<span class="Normal">void</span> initialize_recipe_literal<span class="Delimiter">(</span>reagent&amp; x<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  x<span class="Delimiter">.</span>type = <span class="Normal">new</span> type_tree<span class="Delimiter">(</span><span class="Constant">&quot;recipe-literal&quot;</span><span class="Delimiter">);</span>
  x<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> x<span class="Delimiter">.</span>name<span class="Delimiter">));</span>
<span class="Delimiter">}</span>
<span class="Normal">bool</span> contains_reagent_with_type<span class="Delimiter">(</span><span class="Normal">const</span> recipe&amp; caller<span class="Delimiter">,</span> <span class="Normal">const</span> string&amp; name<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i &lt; SIZE<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
    <span class="Normal">const</span> instruction&amp; inst = caller<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span>
    <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i &lt; SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span>
      <span class="Normal">if</span> <span class="Delimiter">(</span>is_matching_non_recipe_literal<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> name<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span>
    <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i &lt; SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span>
      <span class="Normal">if</span> <span class="Delimiter">(</span>is_matching_non_recipe_literal<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> name<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span>
  <span class="Delimiter">}</span>
  <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
<span class="Normal">bool</span> is_matching_non_recipe_literal<span class="Delimiter">(</span><span class="Normal">const</span> reagent&amp; x<span class="Delimiter">,</span> <span class="Normal">const</span> string&amp; name<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>x<span class="Delimiter">.</span>name != name<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>!x<span class="Delimiter">.</span>type<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>!x<span class="Delimiter">.</span>type<span class="Delimiter">-&gt;</span>atom<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
  <span class="Identifier">return</span> x<span class="Delimiter">.</span>type<span class="Delimiter">-&gt;</span>value != get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">&quot;recipe-literal&quot;</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>

<span class="Comment">//: It's confusing to use variable names that are also recipe names. Always</span>
<span class="Comment">//: assume variable types override recipe literals.</span>
<span class="Delimiter">:(scenario error_on_recipe_literal_used_as_a_variable)</span>
<span class="Special">% Hide_errors = true;</span>
<span class="muRecipe">def</span> main [
  local-scope
  <span class="Normal">a</span>:<span class="Normal">bool</span><span class="Special"> &lt;- </span>equal <span class="Identifier">break</span> <span class="Constant">0</span>
  <span class="Normal">break</span>:<span class="Normal">bool</span><span class="Special"> &lt;- </span>copy <span class="Constant">0</span>
]
<span class="traceContains">+error: main: you can't use 'break' as a recipe literal when it's also a variable</span>
<span class="traceContains">+error: main: missing type for 'break' in 'a:bool &lt;- equal break, 0'</span>

<span class="Delimiter">:(before &quot;End Primitive Recipe Declarations&quot;)</span>
CALL<span class="Delimiter">,</span>
<span class="Delimiter">:(before &quot;End Primitive Recipe Numbers&quot;)</span>
put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">&quot;call&quot;</span><span class="Delimiter">,</span> CALL<span class="Delimiter">);</span>
<span class="Delimiter">:(before &quot;End Primitive Recipe Checks&quot;)</span>
<span class="Normal">case</span> CALL: <span class="Delimiter">{</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span>
    raise &lt;&lt; maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;'call' requires at least one ingredient (the recipe to call)</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
    <span class="Identifier">break</span><span class="Delimiter">;</span>
  <span class="Delimiter">}</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>!is_mu_recipe<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span>
    raise &lt;&lt; maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;first ingredient of 'call' should be a recipe, but got '&quot;</span> &lt;&lt; inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>original_string &lt;&lt; <span class="Constant">&quot;'</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
    <span class="Identifier">break</span><span class="Delimiter">;</span>
  <span class="Delimiter">}</span>
  <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
<span class="Delimiter">:(before &quot;End Primitive Recipe Implementations&quot;)</span>
<span class="Normal">case</span> CALL: <span class="Delimiter">{</span>
  <span class="Comment">// Begin Call</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>Trace_stream<span class="Delimiter">)</span> <span class="Delimiter">{</span>
    ++Trace_stream<span class="Delimiter">-&gt;</span>callstack_depth<span class="Delimiter">;</span>
    trace<span class="Delimiter">(</span><span class="Constant">&quot;trace&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;indirect 'call': incrementing callstack depth to &quot;</span> &lt;&lt; Trace_stream<span class="Delimiter">-&gt;</span>callstack_depth &lt;&lt; end<span class="Delimiter">();</span>
    assert<span class="Delimiter">(</span>Trace_stream<span class="Delimiter">-&gt;</span>callstack_depth &lt; <span class="Constant">9000</span><span class="Delimiter">);</span>  <span class="Comment">// 9998-101 plus cushion</span>
  <span class="Delimiter">}</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>!ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">))</span> <span class="Delimiter">{</span>
    raise &lt;&lt; maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> &lt;&lt; <span class="Constant">&quot;tried to call empty recipe in '&quot;</span> &lt;&lt; to_string<span class="Delimiter">(</span>current_instruction<span class="Delimiter">())</span> &lt;&lt; <span class="Constant">&quot;'&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
    <span class="Identifier">break</span><span class="Delimiter">;</span>
  <span class="Delimiter">}</span>
  <span class="Normal">const</span> instruction&amp; caller_instruction = current_instruction<span class="Delimiter">();</span>
  Current_routine<span class="Delimiter">-&gt;</span>calls<span class="Delimiter">.</span>push_front<span class="Delimiter">(</span>call<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)));</span>
  ingredients<span class="Delimiter">.</span>erase<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>begin<span class="Delimiter">());</span>  <span class="Comment">// drop the callee</span>
  finish_call_housekeeping<span class="Delimiter">(</span>caller_instruction<span class="Delimiter">,</span> ingredients<span class="Delimiter">);</span>
  <span class="Identifier">continue</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>

<span class="SalientComment">//:: check types for 'call' instructions</span>

<span class="Delimiter">:(scenario call_check_literal_recipe)</span>
<span class="Special">% Hide_errors = true;</span>
<span class="muRecipe">def</span> main [
  <span class="Constant">1</span>:num<span class="Special"> &lt;- </span>call f<span class="Delimiter">,</span> <span class="Constant">34</span>
]
<span class="muRecipe">def</span> f x:point<span class="muRecipe"> -&gt; </span>y:point [
  local-scope
  load-ingredients
  y<span class="Special"> &lt;- </span>copy x
]
<span class="traceContains">+error: main: ingredient 0 has the wrong type at '1:num &lt;- call f, 34'</span>
<span class="traceContains">+error: main: product 0 has the wrong type at '1:num &lt;- call f, 34'</span>

<span class="Delimiter">:(scenario call_check_variable_recipe)</span>
<span class="Special">% Hide_errors = true;</span>
<span class="muRecipe">def</span> main [
  <span class="Delimiter">{</span><span class="Constant">1</span>: <span class="Delimiter">(</span>recipe point<span class="muRecipe"> -&gt; </span>point<span class="Delimiter">)}</span><span class="Special"> &lt;- </span>copy f
  <span class="Constant">2</span>:num<span class="Special"> &lt;- </span>call <span class="Delimiter">{</span><span class="Constant">1</span>: <span class="Delimiter">(</span>recipe point<span class="muRecipe"> -&gt; </span>point<span class="Delimiter">)},</span> <span class="Constant">34</span>
]
<span class="muRecipe">def</span> f x:point<span class="muRecipe"> -&gt; </span>y:point [
  local-scope
  load-ingredients
  y<span class="Special"> &lt;- </span>copy x
]
<span class="traceContains">+error: main: ingredient 0 has the wrong type at '2:num &lt;- call {1: (recipe point -&gt; point)}, 34'</span>
<span class="traceContains">+error: main: product 0 has the wrong type at '2:num &lt;- call {1: (recipe point -&gt; point)}, 34'</span>

<span class="Delimiter">:(after &quot;Transform.push_back(check_instruction)&quot;)</span>
Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>check_indirect_calls_against_header<span class="Delimiter">);</span>  <span class="Comment">// idempotent</span>
<span class="Delimiter">:(code)</span>
<span class="Normal">void</span> check_indirect_calls_against_header<span class="Delimiter">(</span><span class="Normal">const</span> recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  trace<span class="Delimiter">(</span><span class="Constant">9991</span><span class="Delimiter">,</span> <span class="Constant">&quot;transform&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;--- type-check 'call' instructions inside recipe &quot;</span> &lt;&lt; get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name &lt;&lt; end<span class="Delimiter">();</span>
  <span class="Normal">const</span> recipe&amp; caller = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">);</span>
  <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i &lt; SIZE<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
    <span class="Normal">const</span> instruction&amp; inst = caller<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span>
    <span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation != CALL<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span>
    <span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">continue</span><span class="Delimiter">;</span>  <span class="Comment">// error raised above</span>
    <span class="Normal">const</span> reagent&amp; callee = inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span>
    <span class="Normal">if</span> <span class="Delimiter">(</span>!is_mu_recipe<span class="Delimiter">(</span>callee<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span>  <span class="Comment">// error raised above</span>
    <span class="Normal">const</span> recipe callee_header = is_literal<span class="Delimiter">(</span>callee<span class="Delimiter">)</span> ? get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> callee<span class="Delimiter">.</span>value<span class="Delimiter">)</span> : from_reagent<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span>
    <span class="Normal">if</span> <span class="Delimiter">(</span>!callee_header<span class="Delimiter">.</span>has_header<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span>
    <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Comment">/*</span><span class="Comment">skip callee</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> i &lt; min<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">),</span> SIZE<span class="Delimiter">(</span>callee_header<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span>+<span class="Comment">/*</span><span class="Comment">skip callee</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
      <span class="Normal">if</span> <span class="Delimiter">(</span>!types_coercible<span class="Delimiter">(</span>callee_header<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i-<span class="Comment">/*</span><span class="Comment">skip callee</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">),</span> inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span>
        raise &lt;&lt; maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;ingredient &quot;</span> &lt;&lt; i-<span class="Comment">/*</span><span class="Comment">skip callee</span><span class="Comment">*/</span><span class="Constant">1</span> &lt;&lt; <span class="Constant">&quot; has the wrong type at '&quot;</span> &lt;&lt; inst<span class="Delimiter">.</span>original_string &lt;&lt; <span class="Constant">&quot;'</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
    <span class="Delimiter">}</span>
    <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i &lt; min<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">),</span> SIZE<span class="Delimiter">(</span>callee_header<span class="Delimiter">.</span>products<span class="Delimiter">));</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
      <span class="Normal">if</span> <span class="Delimiter">(</span>is_dummy<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span>
      <span class="Normal">if</span> <span class="Delimiter">(</span>!types_coercible<span class="Delimiter">(</span>callee_header<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span>
        raise &lt;&lt; maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;product &quot;</span> &lt;&lt; i &lt;&lt; <span class="Constant">&quot; has the wrong type at '&quot;</span> &lt;&lt; inst<span class="Delimiter">.</span>original_string &lt;&lt; <span class="Constant">&quot;'</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
    <span class="Delimiter">}</span>
  <span class="Delimiter">}</span>
<span class="Delimiter">}</span>

<span class="muRecipe">recipe</span> from_reagent<span class="Delimiter">(</span><span class="Normal">const</span> reagent&amp; r<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  assert<span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">);</span>
  recipe result_header<span class="Delimiter">;</span>  <span class="Comment">// will contain only ingredients and products, nothing else</span>
  result_header<span class="Delimiter">.</span>has_header = <span class="Constant">true</span><span class="Delimiter">;</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">-&gt;</span>atom<span class="Delimiter">)</span> <span class="Delimiter">{</span>
    assert<span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">-&gt;</span>name == <span class="Constant">&quot;recipe&quot;</span><span class="Delimiter">);</span>
    <span class="Identifier">return</span> result_header<span class="Delimiter">;</span>
  <span class="Delimiter">}</span>
  assert<span class="Delimiter">(</span>root_type<span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">)-&gt;</span>name == <span class="Constant">&quot;recipe&quot;</span><span class="Delimiter">);</span>
  <span class="Normal">const</span> type_tree* curr = r<span class="Delimiter">.</span>type<span class="Delimiter">-&gt;</span>right<span class="Delimiter">;</span>
  <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">nada</span><span class="Comment">*/</span><span class="Delimiter">;</span> curr &amp;&amp; !curr<span class="Delimiter">-&gt;</span>atom<span class="Delimiter">;</span> curr = curr<span class="Delimiter">-&gt;</span>right<span class="Delimiter">)</span> <span class="Delimiter">{</span>
    <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">-&gt;</span>left<span class="Delimiter">-&gt;</span>atom &amp;&amp; curr<span class="Delimiter">-&gt;</span>left<span class="Delimiter">-&gt;</span>name == <span class="Constant">&quot;-&gt;&quot;</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
      curr = curr<span class="Delimiter">-&gt;</span>right<span class="Delimiter">;</span>  <span class="Comment">// skip delimiter</span>
      <span class="Identifier">goto</span> read_products<span class="Delimiter">;</span>
    <span class="Delimiter">}</span>
    result_header<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>next_recipe_reagent<span class="Delimiter">(</span>curr<span class="Delimiter">-&gt;</span>left<span class="Delimiter">));</span>
  <span class="Delimiter">}</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">)</span> <span class="Delimiter">{</span>
    assert<span class="Delimiter">(</span>curr<span class="Delimiter">-&gt;</span>atom<span class="Delimiter">);</span>
    result_header<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>next_recipe_reagent<span class="Delimiter">(</span>curr<span class="Delimiter">));</span>
    <span class="Identifier">return</span> result_header<span class="Delimiter">;</span>  <span class="Comment">// no products</span>
  <span class="Delimiter">}</span>
  <span class="Normal">read_products</span>:
  <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">nada</span><span class="Comment">*/</span><span class="Delimiter">;</span> curr &amp;&amp; !curr<span class="Delimiter">-&gt;</span>atom<span class="Delimiter">;</span> curr = curr<span class="Delimiter">-&gt;</span>right<span class="Delimiter">)</span>
    result_header<span class="Delimiter">.</span>products<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>next_recipe_reagent<span class="Delimiter">(</span>curr<span class="Delimiter">-&gt;</span>left<span class="Delimiter">));</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">)</span> <span class="Delimiter">{</span>
    assert<span class="Delimiter">(</span>curr<span class="Delimiter">-&gt;</span>atom<span class="Delimiter">);</span>
    result_header<span class="Delimiter">.</span>products<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>next_recipe_reagent<span class="Delimiter">(</span>curr<span class="Delimiter">));</span>
  <span class="Delimiter">}</span>
  <span class="Identifier">return</span> result_header<span class="Delimiter">;</span>
<span class="Delimiter">}</span>

<span class="Delimiter">:(before &quot;End Unit Tests&quot;)</span>
<span class="Normal">void</span> test_from_reagent_atomic<span class="Delimiter">()</span> <span class="Delimiter">{</span>
  reagent a<span class="Delimiter">(</span><span class="Constant">&quot;{f: recipe}&quot;</span><span class="Delimiter">);</span>
  recipe r_header = from_reagent<span class="Delimiter">(</span>a<span class="Delimiter">);</span>
  CHECK<span class="Delimiter">(</span>r_header<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">());</span>
  CHECK<span class="Delimiter">(</span>r_header<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">());</span>
<span class="Delimiter">}</span>
<span class="Normal">void</span> test_from_reagent_non_atomic<span class="Delimiter">()</span> <span class="Delimiter">{</span>
  reagent a<span class="Delimiter">(</span><span class="Constant">&quot;{f: (recipe number -&gt; number)}&quot;</span><span class="Delimiter">);</span>
  recipe r_header = from_reagent<span class="Delimiter">(</span>a<span class="Delimiter">);</span>
  CHECK_EQ<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>r_header<span class="Delimiter">.</span>ingredients<span class="Delimiter">),</span> <span class="Constant">1</span><span class="Delimiter">);</span>
  CHECK_EQ<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>r_header<span class="Delimiter">.</span>products<span class="Delimiter">),</span> <span class="Constant">1</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>
<span class="Normal">void</span> test_from_reagent_reads_ingredient_at_end<span class="Delimiter">()</span> <span class="Delimiter">{</span>
  reagent a<span class="Delimiter">(</span><span class="Constant">&quot;{f: (recipe number number)}&quot;</span><span class="Delimiter">);</span>
  recipe r_header = from_reagent<span class="Delimiter">(</span>a<span class="Delimiter">);</span>
  CHECK_EQ<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>r_header<span class="Delimiter">.</span>ingredients<span class="Delimiter">),</span> <span class="Constant">2</span><span class="Delimiter">);</span>
  CHECK<span class="Delimiter">(</span>r_header<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">());</span>
<span class="Delimiter">}</span>
<span class="Normal">void</span> test_from_reagent_reads_sole_ingredient_at_end<span class="Delimiter">()</span> <span class="Delimiter">{</span>
  reagent a<span class="Delimiter">(</span><span class="Constant">&quot;{f: (recipe number)}&quot;</span><span class="Delimiter">);</span>
  recipe r_header = from_reagent<span class="Delimiter">(</span>a<span class="Delimiter">);</span>
  CHECK_EQ<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>r_header<span class="Delimiter">.</span>ingredients<span class="Delimiter">),</span> <span class="Constant">1</span><span class="Delimiter">);</span>
  CHECK<span class="Delimiter">(</span>r_header<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">());</span>
<span class="Delimiter">}</span>

<span class="Delimiter">:(code)</span>
reagent next_recipe_reagent<span class="Delimiter">(</span><span class="Normal">const</span> type_tree* curr<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>!curr<span class="Delimiter">-&gt;</span>left<span class="Delimiter">)</span> <span class="Identifier">return</span> reagent<span class="Delimiter">(</span><span class="Constant">&quot;recipe:&quot;</span>+curr<span class="Delimiter">-&gt;</span>name<span class="Delimiter">);</span>
  reagent result<span class="Delimiter">;</span>
  result<span class="Delimiter">.</span>name = <span class="Constant">&quot;recipe&quot;</span><span class="Delimiter">;</span>
  result<span class="Delimiter">.</span>type = <span class="Normal">new</span> type_tree<span class="Delimiter">(</span>*curr<span class="Delimiter">-&gt;</span>left<span class="Delimiter">);</span>
  <span class="Identifier">return</span> result<span class="Delimiter">;</span>
<span class="Delimiter">}</span>

<span class="Normal">bool</span> is_mu_recipe<span class="Delimiter">(</span><span class="Normal">const</span> reagent&amp; r<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>!r<span class="Delimiter">.</span>type<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">-&gt;</span>atom<span class="Delimiter">)</span>
    <span class="Identifier">return</span> r<span class="Delimiter">.</span>type<span class="Delimiter">-&gt;</span>name == <span class="Constant">&quot;recipe-literal&quot;</span><span class="Delimiter">;</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>!r<span class="Delimiter">.</span>type<span class="Delimiter">-&gt;</span>left<span class="Delimiter">-&gt;</span>atom<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">-&gt;</span>left<span class="Delimiter">-&gt;</span>name == <span class="Constant">&quot;recipe&quot;</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span>
  <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>

<span class="Delimiter">:(scenario copy_typecheck_recipe_variable)</span>
<span class="Special">% Hide_errors = true;</span>
<span class="muRecipe">def</span> main [
  <span class="Constant">3</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">34</span>  <span class="Comment"># abc def</span>
  <span class="Delimiter">{</span><span class="Constant">1</span>: <span class="Delimiter">(</span>recipe number<span class="muRecipe"> -&gt; </span>number<span class="Delimiter">)}</span><span class="Special"> &lt;- </span>copy f  <span class="Comment"># store literal in a matching variable</span>
  <span class="Delimiter">{</span><span class="Constant">2</span>: <span class="Delimiter">(</span>recipe boolean<span class="muRecipe"> -&gt; </span>boolean<span class="Delimiter">)}</span><span class="Special"> &lt;- </span>copy <span class="Delimiter">{</span><span class="Constant">1</span>: <span class="Delimiter">(</span>recipe number<span class="muRecipe"> -&gt; </span>number<span class="Delimiter">)}</span>  <span class="Comment"># mismatch between recipe variables</span>
]
<span class="muRecipe">def</span> f x:num<span class="muRecipe"> -&gt; </span>y:num [
  local-scope
  load-ingredients
  y<span class="Special"> &lt;- </span>copy x
]
<span class="traceContains">+error: main: can't copy '{1: (recipe number -&gt; number)}' to '{2: (recipe boolean -&gt; boolean)}'; types don't match</span>

<span class="Delimiter">:(scenario copy_typecheck_recipe_variable_2)</span>
<span class="Special">% Hide_errors = true;</span>
<span class="muRecipe">def</span> main [
  <span class="Delimiter">{</span><span class="Constant">1</span>: <span class="Delimiter">(</span>recipe number<span class="muRecipe"> -&gt; </span>number<span class="Delimiter">)}</span><span class="Special"> &lt;- </span>copy f  <span class="Comment"># mismatch with a recipe literal</span>
]
<span class="muRecipe">def</span> f x:<span class="Normal">bool</span><span class="muRecipe"> -&gt; </span>y:<span class="Normal">bool</span> [
  local-scope
  load-ingredients
  y<span class="Special"> &lt;- </span>copy x
]
<span class="traceContains">+error: main: can't copy 'f' to '{1: (recipe number -&gt; number)}'; types don't match</span>

<span class="Delimiter">:(before &quot;End Matching Types For Literal(to)&quot;)</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>is_mu_recipe<span class="Delimiter">(</span>to<span class="Delimiter">))</span> <span class="Delimiter">{</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> from<span class="Delimiter">.</span>value<span class="Delimiter">))</span> <span class="Delimiter">{</span>
    raise &lt;&lt; <span class="Constant">&quot;trying to store recipe &quot;</span> &lt;&lt; from<span class="Delimiter">.</span>name &lt;&lt; <span class="Constant">&quot; into &quot;</span> &lt;&lt; to_string<span class="Delimiter">(</span>to<span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot; but there's no such recipe</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
    <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
  <span class="Delimiter">}</span>
  <span class="Normal">const</span> recipe&amp; rrhs = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> from<span class="Delimiter">.</span>value<span class="Delimiter">);</span>
  <span class="Normal">const</span> recipe&amp; rlhs = from_reagent<span class="Delimiter">(</span>to<span class="Delimiter">);</span>
  <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i &lt; min<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>rlhs<span class="Delimiter">.</span>ingredients<span class="Delimiter">),</span> SIZE<span class="Delimiter">(</span>rrhs<span class="Delimiter">.</span>ingredients<span class="Delimiter">));</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
    <span class="Normal">if</span> <span class="Delimiter">(</span>!types_match<span class="Delimiter">(</span>rlhs<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> rrhs<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span>
      <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
  <span class="Delimiter">}</span>
  <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i &lt; min<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>rlhs<span class="Delimiter">.</span>products<span class="Delimiter">),</span> SIZE<span class="Delimiter">(</span>rrhs<span class="Delimiter">.</span>products<span class="Delimiter">));</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
    <span class="Normal">if</span> <span class="Delimiter">(</span>!types_match<span class="Delimiter">(</span>rlhs<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> rrhs<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span>
      <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
  <span class="Delimiter">}</span>
  <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>

<span class="Delimiter">:(scenario call_variable_compound_ingredient)</span>
<span class="muRecipe">def</span> main [
  <span class="Delimiter">{</span><span class="Constant">1</span>: <span class="Delimiter">(</span>recipe <span class="Delimiter">(</span>address number<span class="Delimiter">)</span><span class="muRecipe"> -&gt; </span>number<span class="Delimiter">)}</span><span class="Special"> &lt;- </span>copy f
  <span class="Constant">2</span>:&amp;:num<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>
  <span class="Constant">3</span>:num<span class="Special"> &lt;- </span>call <span class="Delimiter">{</span><span class="Constant">1</span>: <span class="Delimiter">(</span>recipe <span class="Delimiter">(</span>address number<span class="Delimiter">)</span><span class="muRecipe"> -&gt; </span>number<span class="Delimiter">)},</span> <span class="Constant">2</span>:&amp;:num
]
<span class="muRecipe">def</span> f x:&amp;:num<span class="muRecipe"> -&gt; </span>y:num [
  local-scope
  load-ingredients
  y<span class="Special"> &lt;- </span>copy x
]
$error: <span class="Constant">0</span>

<span class="Comment">//: make sure we don't accidentally break on a function literal</span>
<span class="Delimiter">:(scenario jump_forbidden_on_recipe_literals)</span>
<span class="Special">% Hide_errors = true;</span>
<span class="muRecipe">def</span> foo [
  local-scope
]
<span class="muRecipe">def</span> main [
  local-scope
  <span class="Delimiter">{</span>
    <span class="Identifier">break</span>-<span class="Normal">if</span> foo
  <span class="Delimiter">}</span>
]
<span class="Comment"># error should be as if foo is not a recipe</span>
<span class="traceContains">+error: main: missing type for foo in 'break-if foo'</span>

<span class="Delimiter">:(before &quot;End JUMP_IF Checks&quot;)</span>
check_for_recipe_literals<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">));</span>
<span class="Delimiter">:(before &quot;End JUMP_UNLESS Checks&quot;)</span>
check_for_recipe_literals<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">));</span>
<span class="Delimiter">:(code)</span>
<span class="Normal">void</span> check_for_recipe_literals<span class="Delimiter">(</span><span class="Normal">const</span> instruction&amp; inst<span class="Delimiter">,</span> <span class="Normal">const</span> recipe&amp; caller<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i &lt; SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
    <span class="Normal">if</span> <span class="Delimiter">(</span>is_mu_recipe<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span>
      raise &lt;&lt; maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;missing type for &quot;</span> &lt;&lt; inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>original_string &lt;&lt; <span class="Constant">&quot; in '&quot;</span> &lt;&lt; inst<span class="Delimiter">.</span>original_string &lt;&lt; <span class="Constant">&quot;'</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
  <span class="Delimiter">}</span>
<span class="Delimiter">}</span>
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->