Let-expression
Let expressions are used to declare a variable. For example, we are writing a program to simulate the game of craps. A dice has 6 sides. So this program has been using this number 6 times. One day, we suddenly changed our mind to play 12-sided dice. So we have to look up the source code, the inside of the 6 change to 12. For a larger program, this is the beginning of the disaster. Sometimes we miss out on a few 6, and sometimes we change the number of points that are not the dice to 12. This disaster is called "Magic Numbers". The way to avoid magic numbers is generally to declare a variable--such as a variable (a\)--to make this variable equal to 6 (\ (a=6\)). The Let expression for this example contains three elements: variable \ (a\), to give the variable a value of 6, and the program principal \ (m\). I write this let expression as follows: \[({let} \; a \; 6 \; M) \] Generally, define let expressions as follows: \[({let} \; X \; N \; M) \] This is a let expression of a single variable.
Or the example of a roll of dice. One way to avoid magic numbers is to define a function, the parameter of the function is the number of faces of the dice \ (a\), the function body is the program body \ (m\): \[\lambda a.m \] Then call this function with parameter 6: \[(\lambda a.m \; 6) \] The above expression and let table In contrast, we can see that let expression is just a function call syntax sugar: \[({let} \; X \; N \; M) = (\lambda x.m \; N) \] Based on the principle of simplicity, I do not intend to add let expressions to the syntax of the interpreter, but rather to have letting expressions join the language in the form of macros. So another function translate is written to expand the let expression.
The interpreter invokes the translate to do the conversion, and then calls the value-of for evaluation.
This column more highlights: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/project/