about summary refs log blame commit diff stats
path: root/html/028call_reply.cc.html
blob: 3e4de57dc5c74fc41dc258fa0ac2fe63df98664e (plain) (tree)
e6
=head1 NAME

rifle - ranger's file opener




=head1 SYNOPSIS

B<rifle> [B<--help>] [B<-f> I<FLAGS>] [B<-l>] [B<-p> I<KEYWORD>]
[B<-w> I<PROGRAM>] [B<-c> I<CONFIG_FILE>] I<files>




=head1 DESCRIPTION

rifle is a powerful file executor that allows for complex file type checking,
written to meet the needs of the file manager I<ranger>.  rifle's strength lies
in automatically determining file types, depending on which programs are
installed on the system, even without any user interaction.




=head1 OPTIONS

=over 14

=item B<-f> I<FLAGS>

Specify flags for opening the files.  Flags are letters that changes how the
program is executed.  Any combination of flags will work.  Writing uppercase
flags will negate the effect of all previously used lowercase flags of the same
letter.

Table of all flags:
 f   fork program to background
 r   run program as root, using sudo
 t   run program in a separate terminal, as specified by $TERMCMD

=item B<-l>

List all possible ways to open the specified files.  Each line will contain information in the format of I<id:label:flags:command>. I<id> is the identification number. I<label> is an arbitrary string that was specified for this command, I<flags> are the flags that are used by default, and I<command> is the command that is going to be executed.

=item B<-p> I<KEYWORD>

Pick a method to open the files.

I<KEYWORD> is either the ID number listed by C<rifle -l> or a string that matches a label in the configuration file.

=item B<-w> I<PROGRAM>

Open the files with the program I<PROGRAM>

=item B<-c> I<CONFIG_FILE>

Read configuration from I<CONFIG_FILE>, instead of the default.

=item B<-h>, B<--help>

Print a list of options and exit.

=back




=head1 FILES

rifle shares configuration files with ranger, though ranger is not required in
order to use rifle. The default configuration file F<rifle.conf> is expected
to be at F<~/.config/ranger/rifle.conf>. However, this can be overridden with
the B<-c> option.

This file specifies patterns for determining the commands to open files with.
The syntax is described in the comments of the default F<rifle.conf> that ships
with ranger.  To obtain it, you need to run: C<ranger --copy-config=rifle>




=head1 ENVIRONMENT

=over 8

=item VISUAL

Determines which editor to use for editing files.

=item EDITOR

Determines which editor to use for editing files if VISUAL is undefined or
empty (in the default F<rifle.conf>). If both are undefined or empty, "vim" is
used instead.

=item PAGER

Determines which pager to use for displaying files (in the default F<rifle.conf>).

=item TERMCMD

Determines the terminal emulator command for use with the I<t> flag.  It is required that the value is the path to an executable file which accepts the "-e COMMAND" argument.

=item XDG_CONFIG_HOME

Specifies the directory for configuration files. Defaults to F<$HOME/.config>.

=back




=head1 EXAMPLES

List all the different methods:

 $ rifle -l helloworld.py
 0:editor::"$EDITOR" -- "$@"
 1:pager::"$PAGER" -- "$@"
 2:::python -- "$1"

Display its content by opening it with "cat":

 $ rifle -w cat helloworld.py
 print("Hello World!")

Run it by picking the method 2, which calls 'python -- "$1"':

 $ rifle -p 2 helloworld.py
 Hello World!

Display the file in a pager inside a new terminal, run as root:

 $ rifle -p 1 -f tr helloworld.py
/html/037call_reply.cc.html?h=main&id=20d1c9057a559ce8db83bbc2787ca91348bcb16f'>^
65361948 ^

672e3e50 ^

dea90217 ^
672e3e50 ^
dea90217 ^

76755b28 ^
dea90217 ^
67db19a0 ^
76755b28 ^
672e3e50 ^
dea90217 ^
d5d908dd ^
4690ce81 ^
76755b28 ^

4690ce81 ^
67db19a0 ^


76755b28 ^
65361948 ^

4690ce81 ^
c842d90b ^
67db19a0 ^
83fcebf3 ^
65361948 ^
762b099e ^
e8b1d3ff ^
672e3e50 ^

67db19a0 ^




4690ce81 ^

dcc060c7 ^
a654e4ec ^
4690ce81 ^




a654e4ec ^
4690ce81 ^
dea90217 ^
67db19a0 ^
4690ce81 ^
2f02189d ^
67db19a0 ^

a654e4ec ^
2f02189d ^

dea90217 ^
4690ce81 ^
2f02189d ^
44c1aeef ^
67db19a0 ^




a654e4ec ^
4690ce81 ^
67db19a0 ^
44c1aeef ^
2f02189d ^
67db19a0 ^

a654e4ec ^
4690ce81 ^
a654e4ec ^
d009e158 ^

4690ce81 ^
2f02189d ^
dcc060c7 ^
67db19a0 ^

4690ce81 ^
67db19a0 ^



dea90217 ^
76755b28 ^
4690ce81 ^
f344b250 ^
76755b28 ^
4690ce81 ^
f344b250 ^

76755b28 ^
4690ce81 ^
76755b28 ^
f344b250 ^
76755b28 ^
672e3e50 ^


83fcebf3 ^
65361948 ^
dea90217 ^
76755b28 ^
4690ce81 ^
f344b250 ^

672e3e50 ^
4690ce81 ^
f344b250 ^

672e3e50 ^
f344b250 ^
672e3e50 ^
dea90217 ^
4690ce81 ^
f344b250 ^

d5d908dd ^
4690ce81 ^
f344b250 ^

d5d908dd ^
76755b28 ^
d5d908dd ^
672e3e50 ^
4690ce81 ^

672e3e50 ^
4690ce81 ^
76755b28 ^
672e3e50 ^


a654e4ec ^
4690ce81 ^
76755b28 ^
672e3e50 ^






a654e4ec ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196



                                                                                          
                                    

                                                
                                  

                                                                                         

                       
                                                                                                 
                                                                                            

                                      
                             
                                  
                            



                                                                           

        





                               

       
                         
                                                                                             
 
                                                 
          
                                                                                                                                                                               
 
       


                                                                                                                                                                                  
 

                                                                 

                                                                                      
                                      
                                                                                 

                                                                                                                                                                                                                                                                 
                                                                                
                                                                         
                                                                                                                                                      
                                
                                                                                         
                                                                         
                                                
                                                                                                                                              

                                                                                                                                                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                        


                                                                                                                                     
                                  

                                                                                                                                     
                                                                                                                                                                                                                                                                                                  
                                                                                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                                                                         
                                                                                                                                                                                                                                                                                                                                                                            
                                           
                                                                                                                                                         

                                




                                                                                                                                                    

                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                                                                                                                                    
                                                                                                                                                                                                                                                                                                                                                                  




                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                    
                                                                                                                                                                                                                     
                                                                                                                                                                                                                                           
                                                                 
                                                                                                                                                                                                                                                                                                                                                                    
                                                                                                                                                                                                                                                                                                                                                                      

                                                                             
                                                                                                                                                                                                                                                                                                                                                                                     

                                                                                                                                                                                                                                                                                   
                                                                       
                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        




                                                                                                          
                                                                                                                                                                                                                                                                                                                                                                                     
                                                                                                                                                                                                                                                                                                                                                                                                           
                                                                                                                                                                                                                                                                                                                            
                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      

                                                                                                   
                                                                                                                                                                                    
                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      

                                                                                                   
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
                                          

                                        
                                                                                     



                                    
                                                               
                                                  
          
                                                                                                          
 
       

                                                                                                               
                                                                                                                                                        
                                                                               
 
                                                                                                    
 


                                                                                                         
                                                                                                               
 
                                                                    
                                                  
          

                                                                                                                                                                                             
 
           

                                                                                                                                
 
                                                                                                                      
 
                                                                          
          

                                                                                                                                                           
 
           

                                                                                                                                
 
                                       
 
                                      

                                                                                                                                                                                                                                                              
                                                   
                                                                                                                                                                                                                                           
                                                                                                                                                                                                   


                                                                                                                   
                                                                                                                                                                                                                                                                                                                         
                                                                                                                                                                                                                                   
                                                                                                                                                                     






                                                                                                                 
                                     
<!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 - 028call_reply.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; }
.traceContains { color: #008000; }
.Comment { color: #9090ff; }
.Delimiter { color: #800080; }
.Special { color: #c00000; }
.Identifier { color: #fcb165; }
.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; }
-->
</style>

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

-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="Comment">//: Calls can also generate products, using 'reply' or 'return'.</span>

<span class="Delimiter">:(scenario return)</span>
def main [
  <span class="Constant">1</span>:num<span class="Delimiter">,</span> <span class="Constant">2</span>:num<span class="Special"> &lt;- </span>f <span class="Constant">34</span>
]
def f [
  <span class="Constant">12</span>:num<span class="Special"> &lt;- </span>next-ingredient
  <span class="Constant">13</span>:num<span class="Special"> &lt;- </span>add <span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">12</span>:num
  reply <span class="Constant">12</span>:num<span class="Delimiter">,</span> <span class="Constant">13</span>:num
]
<span class="traceContains">+mem: storing 34 in location 1</span>
<span class="traceContains">+mem: storing 35 in location 2</span>

<span class="Delimiter">:(before &quot;End Primitive Recipe Declarations&quot;)</span>
RETURN<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;return&quot;</span><span class="Delimiter">,</span> RETURN<span class="Delimiter">);</span>
put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">&quot;reply&quot;</span><span class="Delimiter">,</span> RETURN<span class="Delimiter">);</span>  <span class="Comment">// synonym while teaching</span>
<span class="Delimiter">:(before &quot;End Primitive Recipe Checks&quot;)</span>
<span class="Normal">case</span> RETURN: <span class="Delimiter">{</span>
  <span class="Identifier">break</span><span class="Delimiter">;</span>  <span class="Comment">// checks will be performed by a transform below</span>
<span class="Delimiter">}</span>
<span class="Delimiter">:(before &quot;End Primitive Recipe Implementations&quot;)</span>
<span class="Normal">case</span> RETURN: <span class="Delimiter">{</span>
  <span class="Comment">// Starting Reply</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>Trace_stream<span class="Delimiter">)</span> <span class="Delimiter">{</span>
    trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">&quot;trace&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;reply: decrementing callstack depth from &quot;</span> &lt;&lt; Trace_stream<span class="Delimiter">-&gt;</span>callstack_depth &lt;&lt; end<span class="Delimiter">();</span>
    --Trace_stream<span class="Delimiter">-&gt;</span>callstack_depth<span class="Delimiter">;</span>
    <span class="Normal">if</span> <span class="Delimiter">(</span>Trace_stream<span class="Delimiter">-&gt;</span>callstack_depth &lt; <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
      Current_routine<span class="Delimiter">-&gt;</span>calls<span class="Delimiter">.</span>clear<span class="Delimiter">();</span>
      <span class="Identifier">goto</span> stop_running_current_routine<span class="Delimiter">;</span>
    <span class="Delimiter">}</span>
  <span class="Delimiter">}</span>
  Current_routine<span class="Delimiter">-&gt;</span>calls<span class="Delimiter">.</span>pop_front<span class="Delimiter">();</span>
  <span class="Comment">// just in case 'main' returns a value, drop it for now</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>Current_routine<span class="Delimiter">-&gt;</span>calls<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">goto</span> stop_running_current_routine<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>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span>
    trace<span class="Delimiter">(</span><span class="Constant">9998</span><span class="Delimiter">,</span> <span class="Constant">&quot;run&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;result &quot;</span> &lt;&lt; i &lt;&lt; <span class="Constant">&quot; is &quot;</span> &lt;&lt; to_string<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">))</span> &lt;&lt; end<span class="Delimiter">();</span>
  <span class="Comment">// make reply products available to caller</span>
  copy<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> ingredients<span class="Delimiter">.</span>end<span class="Delimiter">(),</span> inserter<span class="Delimiter">(</span>products<span class="Delimiter">,</span> products<span class="Delimiter">.</span>begin<span class="Delimiter">()));</span>
  <span class="Comment">// End Reply</span>
  <span class="Identifier">break</span><span class="Delimiter">;</span>  <span class="Comment">// continue to process rest of *caller* instruction</span>
<span class="Delimiter">}</span>

<span class="Comment">//: Types in reply instructions are checked ahead of time.</span>

<span class="Delimiter">:(before &quot;End Checks&quot;)</span>
Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>check_types_of_reply_instructions<span class="Delimiter">);</span>
<span class="Delimiter">:(code)</span>
<span class="Normal">void</span> check_types_of_reply_instructions<span class="Delimiter">(</span>recipe_ordinal r<span class="Delimiter">)</span> <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>
  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;--- check types of reply instructions in recipe &quot;</span> &lt;&lt; caller<span class="Delimiter">.</span>name &lt;&lt; end<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; caller_instruction = 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>caller_instruction<span class="Delimiter">.</span>is_label<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span>
    <span class="Normal">if</span> <span class="Delimiter">(</span>caller_instruction<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">continue</span><span class="Delimiter">;</span>
    <span class="Normal">if</span> <span class="Delimiter">(</span>caller_instruction<span class="Delimiter">.</span>operation &lt; MAX_PRIMITIVE_RECIPES<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span>
    <span class="Normal">const</span> recipe&amp; callee = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> caller_instruction<span class="Delimiter">.</span>operation<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>callee<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; reply_inst = callee<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>reply_inst<span class="Delimiter">.</span>operation != RETURN<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span>
      <span class="Comment">// check types with the caller</span>
      <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>caller_instruction<span class="Delimiter">.</span>products<span class="Delimiter">)</span> &gt; SIZE<span class="Delimiter">(</span>reply_inst<span class="Delimiter">.</span>ingredients<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;too few values returned from &quot;</span> &lt;&lt; callee<span class="Delimiter">.</span>name &lt;&lt; <span class="cSpecial">'\n'</span> &lt;&lt; end<span class="Delimiter">();</span>
        <span class="Identifier">break</span><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_instruction<span class="Delimiter">.</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
        reagent<span class="Comment">/*</span><span class="Comment">copy</span><span class="Comment">*/</span> lhs = reply_inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span>
        reagent<span class="Comment">/*</span><span class="Comment">copy</span><span class="Comment">*/</span> rhs = caller_instruction<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span>
        <span class="Comment">// End Check RETURN Copy(lhs, rhs)</span>
        <span class="Normal">if</span> <span class="Delimiter">(</span>!types_coercible<span class="Delimiter">(</span>rhs<span class="Delimiter">,</span> lhs<span class="Delimiter">))</span> <span class="Delimiter">{</span>
          raise &lt;&lt; maybe<span class="Delimiter">(</span>callee<span class="Delimiter">.</span>name<span class="Delimiter">)</span> &lt;&lt; reply_inst<span class="Delimiter">.</span>name &lt;&lt; <span class="Constant">&quot; ingredient '&quot;</span> &lt;&lt; lhs<span class="Delimiter">.</span>original_string &lt;&lt; <span class="Constant">&quot;' can't be saved in '&quot;</span> &lt;&lt; rhs<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>
          raise &lt;&lt; <span class="Constant">&quot;  ['&quot;</span> &lt;&lt; to_string<span class="Delimiter">(</span>lhs<span class="Delimiter">.</span>type<span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;' vs '&quot;</span> &lt;&lt; to_string<span class="Delimiter">(</span>rhs<span class="Delimiter">.</span>type<span class="Delimiter">)</span> &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">goto</span> finish_reply_check<span class="Delimiter">;</span>
        <span class="Delimiter">}</span>
      <span class="Delimiter">}</span>
      <span class="Comment">// check that any reply ingredients with /same-as-ingredient connect up</span>
      <span class="Comment">// the corresponding ingredient and product in the caller.</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_instruction<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>has_property<span class="Delimiter">(</span>reply_inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> <span class="Constant">&quot;same-as-ingredient&quot;</span><span class="Delimiter">))</span> <span class="Delimiter">{</span>
          string_tree* tmp = property<span class="Delimiter">(</span>reply_inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> <span class="Constant">&quot;same-as-ingredient&quot;</span><span class="Delimiter">);</span>
          <span class="Normal">if</span> <span class="Delimiter">(</span>!tmp || !tmp<span class="Delimiter">-&gt;</span>atom<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;'same-as-ingredient' metadata should take exactly one value in '&quot;</span> &lt;&lt; to_original_string<span class="Delimiter">(</span>reply_inst<span class="Delimiter">)</span> &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">goto</span> finish_reply_check<span class="Delimiter">;</span>
          <span class="Delimiter">}</span>
          <span class="Normal">int</span> ingredient_index = to_integer<span class="Delimiter">(</span>tmp<span class="Delimiter">-&gt;</span>value<span class="Delimiter">);</span>
          <span class="Normal">if</span> <span class="Delimiter">(</span>ingredient_index &gt;= SIZE<span class="Delimiter">(</span>caller_instruction<span class="Delimiter">.</span>ingredients<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;too few ingredients in '&quot;</span> &lt;&lt; to_original_string<span class="Delimiter">(</span>caller_instruction<span class="Delimiter">)</span> &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">goto</span> finish_reply_check<span class="Delimiter">;</span>
          <span class="Delimiter">}</span>
          <span class="Normal">if</span> <span class="Delimiter">(</span>!is_dummy<span class="Delimiter">(</span>caller_instruction<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">))</span> &amp;&amp; !is_literal<span class="Delimiter">(</span>caller_instruction<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>ingredient_index<span class="Delimiter">))</span> &amp;&amp; caller_instruction<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>name != caller_instruction<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>ingredient_index<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;'&quot;</span> &lt;&lt; to_original_string<span class="Delimiter">(</span>caller_instruction<span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;' should write to '&quot;</span> &lt;&lt; caller_instruction<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>ingredient_index<span class="Delimiter">).</span>original_string &lt;&lt; <span class="Constant">&quot;' rather than '&quot;</span> &lt;&lt; caller_instruction<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<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="Normal">finish_reply_check</span>:<span class="Delimiter">;</span>
    <span class="Delimiter">}</span>
  <span class="Delimiter">}</span>
<span class="Delimiter">}</span>

<span class="Delimiter">:(scenario return_type_mismatch)</span>
<span class="Special">% Hide_errors = true;</span>
def main [
  <span class="Constant">3</span>:num<span class="Special"> &lt;- </span>f <span class="Constant">2</span>
]
def f [
  <span class="Constant">12</span>:num<span class="Special"> &lt;- </span>next-ingredient
  <span class="Constant">13</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">35</span>
  <span class="Constant">14</span>:point<span class="Special"> &lt;- </span>copy <span class="Constant">12</span>:point/<span class="Special">raw</span>
  <span class="Identifier">return</span> <span class="Constant">14</span>:point
]
<span class="traceContains">+error: f: return ingredient '14:point' can't be saved in '3:num'</span>

<span class="Comment">//: In mu we'd like to assume that any instruction doesn't modify its</span>
<span class="Comment">//: ingredients unless they're also products. The /same-as-ingredient inside</span>
<span class="Comment">//: the recipe's 'reply' will help catch accidental misuse of such</span>
<span class="Comment">//: 'ingredient-products' (sometimes called in-out parameters in other languages).</span>

<span class="Delimiter">:(scenario return_same_as_ingredient)</span>
<span class="Special">% Hide_errors = true;</span>
def main [
  <span class="Constant">1</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>
  <span class="Constant">2</span>:num<span class="Special"> &lt;- </span>test1 <span class="Constant">1</span>:num  <span class="Comment"># call with different ingredient and product</span>
]
def test1 [
  <span class="Constant">10</span>:num<span class="Special"> &lt;- </span>next-ingredient
  <span class="Identifier">return</span> <span class="Constant">10</span>:num/same-as-ingredient:<span class="Constant">0</span>
]
<span class="traceContains">+error: main: '2:num &lt;- test1 1:num' should write to '1:num' rather than '2:num'</span>

<span class="Delimiter">:(scenario return_same_as_ingredient_dummy)</span>
def main [
  <span class="Constant">1</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>
  _<span class="Special"> &lt;- </span>test1 <span class="Constant">1</span>:num  <span class="Comment"># call with different ingredient and product</span>
]
def test1 [
  <span class="Constant">10</span>:num<span class="Special"> &lt;- </span>next-ingredient
  <span class="Identifier">return</span> <span class="Constant">10</span>:num/same-as-ingredient:<span class="Constant">0</span>
]
$error: <span class="Constant">0</span>

<span class="Delimiter">:(code)</span>
string to_string<span class="Delimiter">(</span><span class="Normal">const</span> vector&lt;<span class="Normal">double</span>&gt;&amp; in<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>in<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">&quot;[]&quot;</span><span class="Delimiter">;</span>
  ostringstream out<span class="Delimiter">;</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>in<span class="Delimiter">)</span> == <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
    out &lt;&lt; no_scientific<span class="Delimiter">(</span>in<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span>
    <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span>
  <span class="Delimiter">}</span>
  out &lt;&lt; <span class="Constant">&quot;[&quot;</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>in<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
    <span class="Normal">if</span> <span class="Delimiter">(</span>i &gt; <span class="Constant">0</span><span class="Delimiter">)</span> out &lt;&lt; <span class="Constant">&quot;, &quot;</span><span class="Delimiter">;</span>
    out &lt;&lt; no_scientific<span class="Delimiter">(</span>in<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span>
  <span class="Delimiter">}</span>
  out &lt;&lt; <span class="Constant">&quot;]&quot;</span><span class="Delimiter">;</span>
  <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span>
<span class="Delimiter">}</span>
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->