Repository: source-academy/js-slang
Pull request #71 (2018-09-30 04:31:07)

prepared for Week 7
Notable changes for Source §3: set_head and set_tail should return undefined.

Also: I removed object syntax from Source §3. Removal of object support from Source §3 is not critical, but I'd like to reserve object support for Unit 4 of the module.

coveralls: ## Pull Request Test Coverage Report for [Build 111](https://coveralls.io/builds/19266717)

* **0** of **0**   changed or added relevant lines in **0** files are covered.
* No unchanged relevant lines lost coverage.
* Overall coverage remained the same at **57.619%**

---



|  Totals | [![Coverage Status](https://coveralls.io/builds/19266717/badge)](https://coveralls.io/builds/19266717) |
| :-- | --: |
| Change from base [Build 97](https://coveralls.io/builds/19138643): |  0.0% |
| Covered Lines: | 738 |
| Relevant Lines: | 1204 |

---
##### 💛  - [Coveralls](https://coveralls.io)


Patch:
diff --git a/doc/source_1.tex b/doc/source_1.tex
index fe452adf..b4518fea 100644
--- a/doc/source_1.tex
+++ b/doc/source_1.tex
@@ -14,8 +14,7 @@
                                            \textbf{\texttt{=}}\  \textit{expression} \ \textbf{\texttt{;}}
                                                            && \textrm{constant declaration} \\
 &&                       && |   &\quad && \textbf{\texttt{function}}\  \textit{name} \ 
-                                   \textbf{\texttt{(}}\  \textit{parameters} \ \textbf{\texttt{)}}\\
-&&                       &&     &      && \textbf{\texttt{\{}}\  \textit{statement}   \ \textbf{\texttt{\}}} \quad
+                                   \textbf{\texttt{(}}\  \textit{parameters} \ \textbf{\texttt{)}}\ \textit{block} \quad
                                                            && \textrm{function declaration}\\
 &&                       && |   &\quad && \textbf{\texttt{return}}\  \textit{expression} \ \textbf{\texttt{;}}
                                                            && \textrm{return statement}\\
@@ -23,6 +22,8 @@
                                                            && \textrm{conditional statement}\\
 &&                       && |   &\quad &&  \textit{statement} \ 
                                     \textit{statement}     && \textrm{statement sequence} \\
+&&                       && |   &\quad &&  \textit{block} 
+                                                           && \textrm{block statement}\\
 &&                       && |   &\quad &&  \textit{expression} \ \textbf{\texttt{;}}
                                                            && \textrm{expression statement} \\[1mm] 
 && \textit{parameters}   && ::= &\quad &&  \epsilon\ | \  \textit{name} \ 
@@ -30,12 +31,14 @@
                                                             && \textrm{function parameters}   \\[1mm]
 && \textit{if-statement} && ::= &\quad &&  \textbf{\texttt{if}}\
                                    \textbf{\texttt{(}}\ \textit{expression} \ \textbf{\texttt{)}}\ 
-                                   \textbf{\texttt{\{}}\ \textit{statement} \ \textbf{\texttt{\}}}\\
+                                   \textit{block} \\
 &&                       &&     &      && \textbf{\texttt{else}}\
-                                          (\ \textbf{\texttt{\{}}\ \textit{statement}\ \textbf{\texttt{\}}}
+                                          (\ \textit{block}
                                           \ | \
                                           \textit{if-statement} \ )
                                                             && \textrm{conditional statement}   \\[1mm]
+&& \textit{block}        && ::= &      && \textbf{\texttt{\{}}\  \textit{statement}   \ \textbf{\texttt{\}}} \quad
+                                                           && \textrm{block statement}\\[1mm]         
 && \textit{expression}   && ::= &\quad &&  \textit{number}   && \textrm{primitive number expression}\\
 &&                       && |   &\quad && \textbf{\texttt{true}}\ |\ \textbf{\texttt{false}}
                                                            && \textrm{primitive boolean expression}\\
@@ -50,7 +53,7 @@
 &&                       && |   &\quad &&   \textit{expression} \ 
                                             \textbf{\texttt{(}}\ \textit{expressions}\
                                             \textbf{\texttt{)}}
-                                                           && \textrm{(compound) function application}\\
+                                                           && \textrm{function application}\\
 &&                       && |   &\quad &&   (\ \textit{name}\ | \
                                                \textbf{\texttt{(}}\ \textit{parameters}\ \textbf{\texttt{)}}\
                                             )\    
@@ -77,6 +80,8 @@
                                                             && \textrm{argument expressions} 
 \end{alignat*}
 
+\newpage
+
 \input source_return
 
 \input source_names
diff --git a/doc/source_2.tex b/doc/source_2.tex
index 571c9938..19c06922 100644
--- a/doc/source_2.tex
+++ b/doc/source_2.tex
@@ -15,6 +15,8 @@ Compared to Source \S 1, Source \S 2 has the following changes:
 \item List library: Functions for creating, accessing and processing lists.
 \end{itemize}
 
+\newpage
+
 \input source_bnf.tex
 
 \begin{alignat*}{9}
@@ -22,8 +24,7 @@ Compared to Source \S 1, Source \S 2 has the following changes:
                                            \textbf{\texttt{=}}\  \textit{expression} \ \textbf{\texttt{;}}
                                                            && \textrm{constant declaration} \\
 &&                       && |   &\quad && \textbf{\texttt{function}}\  \textit{name} \ 
-                                   \textbf{\texttt{(}}\  \textit{parameters} \ \textbf{\texttt{)}}\\
-&&                       &&     &      && \textbf{\texttt{\{}}\  \textit{statement}   \ \textbf{\texttt{\}}} \quad
+                                   \textbf{\texttt{(}}\  \textit{parameters} \ \textbf{\texttt{)}}\ \textit{block} \quad
                                                            && \textrm{function declaration}\\
 &&                       && |   &\quad && \textbf{\texttt{return}}\  \textit{expression} \ \textbf{\texttt{;}}
                                                            && \textrm{return statement}\\
@@ -31,6 +32,8 @@ Compared to Source \S 1, Source \S 2 has the following changes:
                                                            && \textrm{conditional statement}\\
 &&                       && |   &\quad &&  \textit{statement} \ 
                                     \textit{statement}     && \textrm{statement sequence} \\
+&&                       && |   &\quad &&  \textit{block} 
+                                                           && \textrm{block statement}\\
 &&                       && |   &\quad &&  \textit{expression} \ \textbf{\texttt{;}}
                                                            && \textrm{expression statement} \\[1mm] 
 && \textit{parameters}   && ::= &\quad &&  \epsilon\ | \  \textit{name} \ 
@@ -38,12 +41,14 @@ Compared to Source \S 1, Source \S 2 has the following changes:
                                                             && \textrm{function parameters}   \\[1mm]
 && \textit{if-statement} && ::= &\quad &&  \textbf{\texttt{if}}\
                                    \textbf{\texttt{(}}\ \textit{expression} \ \textbf{\texttt{)}}\ 
-                                   \textbf{\texttt{\{}}\ \textit{statement} \ \textbf{\texttt{\}}}\\
+                                   \textit{block} \\
 &&                       &&     &      && \textbf{\texttt{else}}\
-                                          (\ \textbf{\texttt{\{}}\ \textit{statement}\ \textbf{\texttt{\}}}
+                                          (\ \textit{block}
                                           \ | \
                                           \textit{if-statement} \ )
                                                             && \textrm{conditional statement}   \\[1mm]
+&& \textit{block}        && ::= &      && \textbf{\texttt{\{}}\  \textit{statement}   \ \textbf{\texttt{\}}} \quad
+                                                           && \textrm{block statement}\\[1mm]         
 && \textit{expression}   && ::= &\quad &&  \textit{number}   && \textrm{primitive number expression}\\
 &&                       && |   &\quad && \textbf{\texttt{true}}\ |\ \textbf{\texttt{false}}
                                                            && \textrm{primitive boolean expression}\\
@@ -58,7 +63,7 @@ Compared to Source \S 1, Source \S 2 has the following changes:
 &&                       && |   &\quad &&   \textit{expression} \ 
                                             \textbf{\texttt{(}}\ \textit{expressions}\
                                             \textbf{\texttt{)}}
-                                                           && \textrm{(compound) function application}\\
+                                                           && \textrm{function application}\\
 &&                       && |   &\quad &&   (\ \textit{name}\ | \
                                                \textbf{\texttt{(}}\ \textit{parameters}\ \textbf{\texttt{)}}\
                                             )\    
diff --git a/doc/source_3.tex b/doc/source_3.tex
index b5539576..4f898530 100644
--- a/doc/source_3.tex
+++ b/doc/source_3.tex
@@ -13,49 +13,45 @@ Compared to Source \S 2, Source \S 3 has the following changes:
 \begin{itemize}
 \item variable declaration
 \item variable assignment
-\item array/object assignment
+\item array assignment
 \item \textbf{\texttt{while}} loops
 \item \textbf{\texttt{for}} loops
 \item \textbf{\texttt{break}} and \textbf{\texttt{continue}}
-\item array/object access expressions
-\item literal object expressions
-\item dot abbreviation (see Section \textbf{Objects})
+\item array access expressions
 \end{itemize}
 
+\newpage
+
 \input source_bnf.tex
 
 \begin{alignat*}{9}
 && \textit{statement}    &&\quad ::= &\quad && \textbf{\texttt{const}}\  \textit{name} \ 
                                            \textbf{\texttt{=}}\  \textit{expression} \ \textbf{\texttt{;}}
                                                            && \textrm{constant declaration} \\
-&&                       && |   &\quad && \textbf{\texttt{let}}\  \textit{name} \ 
-                                           \textbf{\texttt{=}}\  \textit{expression} \ \textbf{\texttt{;}}
+&&                       && |   &\quad && \textit{let} \ \textbf{\texttt{;}}
                                                            && \textrm{variable declaration} \\
-&&                       && |   &\quad && \textit{name} \ 
-                                           \textbf{\texttt{=}}\  \textit{expression} \ \textbf{\texttt{;}}
+&&                       && |   &\quad && \textit{assignment} \ \textbf{\texttt{;}}
                                                            && \textrm{variable assignment} \\
 &&                       && |   &\quad && \textit{expression} \textbf{\texttt{[}}
                                           \textit{expression} \textbf{\texttt{]}}
                                            \textbf{\texttt{=}}\  \textit{expression} \ \textbf{\texttt{;}}
-                                                           && \textrm{array/object assignment} \\
+                                                           && \textrm{array assignment} \\
 &&                       && |   &\quad && \textbf{\texttt{function}}\  \textit{name} \ 
-                                   \textbf{\texttt{(}}\  \textit{parameters} \ \textbf{\texttt{)}}\\
-&&                       &&     &      && \textbf{\texttt{\{}}\  \textit{statement}   \ \textbf{\texttt{\}}} 
+                                   \textbf{\texttt{(}}\  \textit{parameters} \ \textbf{\texttt{)}}\ \textit{block} \quad
                                                            && \textrm{function declaration}\\
 &&                       && |   &\quad && \textbf{\texttt{return}}\  \textit{expression} \ \textbf{\texttt{;}}
                                                            && \textrm{return statement}\\
 &&                       && |   &\quad && \textit{if-statement} \quad
                                                            && \textrm{conditional statement}\\
 &&                       && |   &\quad && \textbf{\texttt{while}}\  
-                                   \textbf{\texttt{(}}\  \textit{expression} \ \textbf{\texttt{)}}\\
-&&                       &&     &      && \textbf{\texttt{\{}}\  \textit{statement}   \ \textbf{\texttt{\}}} 
+                                   \textbf{\texttt{(}}\  \textit{expression} \ \textbf{\texttt{)}} \
+                                   \textit{block}
                                                            && \textrm{while loop}\\
-&&                       && |   &\quad && \textbf{\texttt{for}}\  
-                                   \textbf{\texttt{(}}\  \textit{expression} \
-                                   \textbf{\texttt{;}} \  \textit{expression} \
-                                   \textbf{\texttt{;}} \  \textit{expression} \
-                                   \textbf{\texttt{)}}\\
-&&                       &&     &      && \textbf{\texttt{\{}}\  \textit{statement}   \ \textbf{\texttt{\}}} 
+&&                       && |   &\quad && \textbf{\texttt{for}}\ \textbf{\texttt{(}} \ 
+                                          (\ \textit{assignment} \ | \  \textit{let}\ ) \textbf{\texttt{;}} \\
+&&                       &&     &\quad && \ \ \ \ \ \ \ \ \ \ \textit{expression} \ \textbf{\texttt{;}} \\
+&&                       &&     &\quad && \ \ \ \ \ \ \ \ \ \ \textit{assignment} \ \textbf{\texttt{)}} \ 
+                                            \textit{block}
                                                            && \textrm{for loop}\\
 &&                       && |   &\quad && \textbf{\texttt{break}}\ \textbf{\texttt{;}}
                                                            && \textrm{break statement}\\
@@ -63,6 +59,8 @@ Compared to Source \S 2, Source \S 3 has the following changes:
                                                            && \textrm{continue statement}\\
 &&                       && |   &\quad &&  \textit{statement} \ 
                                     \textit{statement}     && \textrm{statement sequence} \\
+&&                       && |   &\quad &&  \textit{block} 
+                                                           && \textrm{block statement}\\
 &&                       && |   &\quad &&  \textit{expression} \ \textbf{\texttt{;}}
                                                            && \textrm{expression statement} \\[1mm] 
 && \textit{parameters}   && ::= &\quad &&  \epsilon\ | \  \textit{name} \ 
@@ -70,12 +68,20 @@ Compared to Source \S 2, Source \S 3 has the following changes:
                                                             && \textrm{function parameters}   \\[1mm]
 && \textit{if-statement} && ::= &\quad &&  \textbf{\texttt{if}}\
                                    \textbf{\texttt{(}}\ \textit{expression} \ \textbf{\texttt{)}}\ 
-                                   \textbf{\texttt{\{}}\ \textit{statement} \ \textbf{\texttt{\}}}\\
+                                   \textit{block} \\
 &&                       &&     &      && \textbf{\texttt{else}}\
-                                          (\ \textbf{\texttt{\{}}\ \textit{statement}\ \textbf{\texttt{\}}}
+                                          (\ \textit{block}
                                           \ | \
                                           \textit{if-statement} \ )
                                                             && \textrm{conditional statement}   \\[1mm]
+&& \textit{block}        && ::= &      && \textbf{\texttt{\{}}\  \textit{statement}   \ \textbf{\texttt{\}}} \quad
+                                                           && \textrm{block statement}\\[1mm]         
+&& \textit{let}          && ::= &\quad &&  \textbf{\texttt{let}}\  \textit{name} \ 
+                                           \textbf{\texttt{=}}\  \textit{expression} 
+                                                            && \textrm{variable declaration}   \\[1mm]
+&& \textit{assignment}   && ::= &\quad &&  \textit{name} \ 
+                                           \textbf{\texttt{=}}\  \textit{expression} 
+                                                            && \textrm{variable assignment}   \\[1mm]
 && \textit{expression}   && ::= &\quad &&  \textit{number}   && \textrm{primitive number expression}\\
 &&                       && |   &\quad && \textbf{\texttt{true}}\ |\ \textbf{\texttt{false}}
                                                            && \textrm{primitive boolean expression}\\
@@ -90,7 +96,7 @@ Compared to Source \S 2, Source \S 3 has the following changes:
 &&                       && |   &\quad &&   \textit{expression} \ 
                                             \textbf{\texttt{(}}\ \textit{expressions}\
                                             \textbf{\texttt{)}}
-                                                           && \textrm{(compound) function application}\\
+                                                           && \textrm{function application}\\
 &&                       && |   &\quad &&   (\ \textit{name}\ | \
                                                \textbf{\texttt{(}}\ \textit{parameters}\ \textbf{\texttt{)}}\
                                             )\    
@@ -105,11 +111,7 @@ Compared to Source \S 2, Source \S 3 has the following changes:
                                                            && \textrm{empty list/array expression}\\
 &&                       && |   &\quad && \textit{expression} \textbf{\texttt{[}}
                                           \textit{expression} \textbf{\texttt{]}}
-                                                           && \textrm{array/object access} \\
-&&                       && |   &\quad &&   \textbf{\texttt{\{}}\ 
-                                            \textit{properties}\
-                                            \textbf{\texttt{\}}}
-                                                           && \textrm{literal object expression}\\
+                                                           && \textrm{array access} \\
 &&                       && |   &\quad &&  \textbf{\texttt{(}}\  \textit{expression} \ 
                                             \textbf{\texttt{)}} && \textrm{parenthesised expression}\\[1mm]
 && \textit{binary-operator}    \ 
@@ -123,23 +125,19 @@ Compared to Source \S 2, Source \S 3 has the following changes:
                                                                \ \textbf{\texttt{,}} \
                                                                  \textit{expression} \ 
                                                                       )\ \ldots
-                                                            && \textrm{argument expressions} \\[1mm]
-&& \textit{properties}  && ::= &\quad && \epsilon\ | \ \textit{property}\ (
-                                                               \ \textbf{\texttt{,}} \
-                                                                 \textit{property} \ 
-                                                                      )\ \ldots
-                                                            && \textrm{object properties} \\[1mm]
-&& \textit{property}  && ::= &\quad && (\ \textit{string}\ |\ \textit{name}\ ) 
-                                        \ \textbf{\texttt{:}} \ \textit{expression} 
-                                                            && \textrm{object property}
+                                                            && \textrm{argument expressions}
 \end{alignat*}
 
-\input source_return
+\newpage
+
+\input source_return_3
 
 \input source_names
 
 \input source_lists
 
+\input source_pair_mutators
+
 \input source_array_support
 
 \input source_numbers
@@ -148,8 +146,6 @@ Compared to Source \S 2, Source \S 3 has the following changes:
 
 \input source_arrays
 
-\input source_objects
-
 \input source_typing
 
 \input source_comments
diff --git a/doc/source_4.tex b/doc/source_4.tex
index 44a7edc5..d2025855 100644
--- a/doc/source_4.tex
+++ b/doc/source_4.tex
@@ -9,7 +9,11 @@
 
 \section*{Changes}
 
-Source \S 4 adds the functions \lstinline{parse},
+Compared to Source \S 3, Source \S 4 has the following changes:
+\begin{itemize}
+\item literal object expressions
+\item dot abbreviation (see Section \textbf{Objects})
+\item Source \S 4 adds the functions \lstinline{parse},
 \lstinline{apply_in_underlying_javascript}, and
 \lstinline{JSON.stringify}.
 Furthermore, the functions \lstinline{is_boolean}, \lstinline{is_number},
@@ -18,7 +22,7 @@ Furthermore, the functions \lstinline{is_boolean}, \lstinline{is_number},
 Following JavaScript, \lstinline{is_object} returns \lstinline{true} when
 applied to arrays. For details, see 
 Section ``Interpreter Support'' below.
-
+\end{itemize}
 
 \input source_bnf.tex
 
@@ -26,34 +30,30 @@ Section ``Interpreter Support'' below.
 && \textit{statement}    &&\quad ::= &\quad && \textbf{\texttt{const}}\  \textit{name} \ 
                                            \textbf{\texttt{=}}\  \textit{expression} \ \textbf{\texttt{;}}
                                                            && \textrm{constant declaration} \\
-&&                       && |   &\quad && \textbf{\texttt{let}}\  \textit{name} \ 
-                                           \textbf{\texttt{=}}\  \textit{expression} \ \textbf{\texttt{;}}
+&&                       && |   &\quad && \textit{let} \ \textbf{\texttt{;}}
                                                            && \textrm{variable declaration} \\
-&&                       && |   &\quad && \textit{name} \ 
-                                           \textbf{\texttt{=}}\  \textit{expression} \ \textbf{\texttt{;}}
+&&                       && |   &\quad && \textit{assignment} \ \textbf{\texttt{;}}
                                                            && \textrm{variable assignment} \\
 &&                       && |   &\quad && \textit{expression} \textbf{\texttt{[}}
                                           \textit{expression} \textbf{\texttt{]}}
                                            \textbf{\texttt{=}}\  \textit{expression} \ \textbf{\texttt{;}}
                                                            && \textrm{array/object assignment} \\
 &&                       && |   &\quad && \textbf{\texttt{function}}\  \textit{name} \ 
-                                   \textbf{\texttt{(}}\  \textit{parameters} \ \textbf{\texttt{)}}\\
-&&                       &&     &      && \textbf{\texttt{\{}}\  \textit{statement}   \ \textbf{\texttt{\}}} 
+                                   \textbf{\texttt{(}}\  \textit{parameters} \ \textbf{\texttt{)}}\ \textit{block} \quad
                                                            && \textrm{function declaration}\\
 &&                       && |   &\quad && \textbf{\texttt{return}}\  \textit{expression} \ \textbf{\texttt{;}}
                                                            && \textrm{return statement}\\
 &&                       && |   &\quad && \textit{if-statement} \quad
                                                            && \textrm{conditional statement}\\
 &&                       && |   &\quad && \textbf{\texttt{while}}\  
-                                   \textbf{\texttt{(}}\  \textit{expression} \ \textbf{\texttt{)}}\\
-&&                       &&     &      && \textbf{\texttt{\{}}\  \textit{statement}   \ \textbf{\texttt{\}}} 
+                                   \textbf{\texttt{(}}\  \textit{expression} \ \textbf{\texttt{)}} \
+                                   \textit{block}
                                                            && \textrm{while loop}\\
-&&                       && |   &\quad && \textbf{\texttt{for}}\  
-                                   \textbf{\texttt{(}}\  \textit{expression} \
-                                   \textbf{\texttt{;}} \  \textit{expression} \
-                                   \textbf{\texttt{;}} \  \textit{expression} \
-                                   \textbf{\texttt{)}}\\
-&&                       &&     &      && \textbf{\texttt{\{}}\  \textit{statement}   \ \textbf{\texttt{\}}} 
+&&                       && |   &\quad && \textbf{\texttt{for}}\ \textbf{\texttt{(}} \ 
+                                          (\ \textit{assignment} \ | \  \textit{let}\ ) \textbf{\texttt{;}} \\
+&&                       &&     &\quad && \ \ \ \ \ \ \ \ \ \ \textit{expression} \ \textbf{\texttt{;}} \\
+&&                       &&     &\quad && \ \ \ \ \ \ \ \ \ \ \textit{assignment} \ \textbf{\texttt{)}} \ 
+                                            \textit{block}
                                                            && \textrm{for loop}\\
 &&                       && |   &\quad && \textbf{\texttt{break}}\ \textbf{\texttt{;}}
                                                            && \textrm{break statement}\\
@@ -61,6 +61,8 @@ Section ``Interpreter Support'' below.
                                                            && \textrm{continue statement}\\
 &&                       && |   &\quad &&  \textit{statement} \ 
                                     \textit{statement}     && \textrm{statement sequence} \\
+&&                       && |   &\quad &&  \textit{block} 
+                                                           && \textrm{block statement}\\
 &&                       && |   &\quad &&  \textit{expression} \ \textbf{\texttt{;}}
                                                            && \textrm{expression statement} \\[1mm] 
 && \textit{parameters}   && ::= &\quad &&  \epsilon\ | \  \textit{name} \ 
@@ -68,12 +70,20 @@ Section ``Interpreter Support'' below.
                                                             && \textrm{function parameters}   \\[1mm]
 && \textit{if-statement} && ::= &\quad &&  \textbf{\texttt{if}}\
                                    \textbf{\texttt{(}}\ \textit{expression} \ \textbf{\texttt{)}}\ 
-                                   \textbf{\texttt{\{}}\ \textit{statement} \ \textbf{\texttt{\}}}\\
+                                   \textit{block} \\
 &&                       &&     &      && \textbf{\texttt{else}}\
-                                          (\ \textbf{\texttt{\{}}\ \textit{statement}\ \textbf{\texttt{\}}}
+                                          (\ \textit{block}
                                           \ | \
                                           \textit{if-statement} \ )
                                                             && \textrm{conditional statement}   \\[1mm]
+&& \textit{block}        && ::= &      && \textbf{\texttt{\{}}\  \textit{statement}   \ \textbf{\texttt{\}}} \quad
+                                                           && \textrm{block statement}\\[1mm]         
+&& \textit{let}          && ::= &\quad &&  \textbf{\texttt{let}}\  \textit{name} \ 
+                                           \textbf{\texttt{=}}\  \textit{expression} 
+                                                            && \textrm{variable declaration}   \\[1mm]
+&& \textit{assignment}   && ::= &\quad &&  \textit{name} \ 
+                                           \textbf{\texttt{=}}\  \textit{expression} 
+                                                            && \textrm{variable assignment}   \\[1mm]
 && \textit{expression}   && ::= &\quad &&  \textit{number}   && \textrm{primitive number expression}\\
 &&                       && |   &\quad && \textbf{\texttt{true}}\ |\ \textbf{\texttt{false}}
                                                            && \textrm{primitive boolean expression}\\
@@ -88,7 +98,7 @@ Section ``Interpreter Support'' below.
 &&                       && |   &\quad &&   \textit{expression} \ 
                                             \textbf{\texttt{(}}\ \textit{expressions}\
                                             \textbf{\texttt{)}}
-                                                           && \textrm{(compound) function application}\\
+                                                           && \textrm{function application}\\
 &&                       && |   &\quad &&   (\ \textit{name}\ | \
                                                \textbf{\texttt{(}}\ \textit{parameters}\ \textbf{\texttt{)}}\
                                             )\    
@@ -132,12 +142,16 @@ Section ``Interpreter Support'' below.
                                                             && \textrm{object property}
 \end{alignat*}
 
-\input source_return
+\newpage
+
+\input source_return_3
 
 \input source_names
 
 \input source_lists
 
+\input source_pair_mutators
+
 \input source_array_support
 
 \input source_numbers
diff --git a/doc/source_arrays.tex b/doc/source_arrays.tex
index cbc0da09..79621204 100644
--- a/doc/source_arrays.tex
+++ b/doc/source_arrays.tex
@@ -2,7 +2,7 @@
 
 Arrays in Source are created using the empty array syntax:
 \begin{lstlisting}
-var my_array = [];
+let my_array = [];
 \end{lstlisting}
 Arrays in Source are limited to integers as keys.
 In statements like
diff --git a/doc/source_header.tex b/doc/source_header.tex
index d9d51364..07d5b263 100644
--- a/doc/source_header.tex
+++ b/doc/source_header.tex
@@ -10,7 +10,7 @@
 \usepackage{listings}
 
 \lstdefinelanguage{JavaScript}{
-  keywords={const, break, case, catch, continue, debugger, default, delete, do, else, finally, for, function, if, in, instanceof, new, return, switch, this, throw, try, typeof, var, void, while, with},
+  keywords={const, let, break, case, catch, continue, debugger, default, delete, do, else, finally, for, function, if, in, instanceof, new, return, switch, this, throw, try, typeof, var, void, while, with},
   morecomment=[l]{//},
   morecomment=[s]{/*}{*/},
   morestring=[b]',
diff --git a/doc/source_names.tex b/doc/source_names.tex
index b167fefa..3f570173 100644
--- a/doc/source_names.tex
+++ b/doc/source_names.tex
@@ -37,8 +37,9 @@ JavaScript
 \item \verb#math_sqrt#\texttt{(n)}: Returns the square root of the \emph{number} \texttt{n}.
 \end{itemize}
 \item \texttt{runtime()}: Returns number of milliseconds elapsed since January 1, 1970 00:00:00 UTC
-\item \texttt{display(a)}: Displays \emph{any} value \texttt{a} in the console
-\item \texttt{error(a)}: Displays \emph{any} value \texttt{a} in the console with error flag
+\item \texttt{display(a)}: Displays \emph{any} value \texttt{a} in the console; returns \texttt{undefined}.
+\item \texttt{error(a)}: Displays \emph{any} value \texttt{a} in the console with error flag. The evaluation
+  of any call of \texttt{error} aborts the running program immediately.
 \item \texttt{prompt(s)}: Pops up a window that displays the \emph{string} \texttt{s}, provides
 an input line for the user to enter a text and an ``OK'' button. The call of \texttt{prompt}
 suspends execution of the program until the ``OK'' button is pressed, at which point it
diff --git a/doc/source_pair_mutators.tex b/doc/source_pair_mutators.tex
new file mode 100644
index 00000000..6f793e78
--- /dev/null
+++ b/doc/source_pair_mutators.tex
@@ -0,0 +1,14 @@
+\subsection*{Pair Mutators}
+
+The following pair mutator functions are supported:
+
+\begin{itemize}
+\item \lstinline{set_head(p, x)}: Changes the pair \lstinline{p} such that its head is \lstinline{x}.
+Returns \lstinline{undefined}.
+\item \lstinline{set_tail(p, x)}: Changes the pair \lstinline{p} such that its tail is \lstinline{x}.
+Returns \lstinline{undefined}.
+\end{itemize}
+
+  
+
+
diff --git a/doc/source_return.tex b/doc/source_return.tex
index 15801dae..6e4bbc37 100644
--- a/doc/source_return.tex
+++ b/doc/source_return.tex
@@ -1,4 +1,4 @@
-\section*{\textrm{return} statements and function definition expressions}
+\section*{Restrictions}
 
 \begin{itemize}
 \item Return statements are only allowed in bodies of functions.
@@ -8,5 +8,6 @@ $\textbf{\texttt{return}}$ and $\textit{expression}$ in return statements.
   $(\ \textit{name}\ | \ \textbf{\texttt{(}}\ \textit{parameters}\ \textbf{\texttt{)}}\ )$
                                                and
 $\texttt{\textbf{=>}}$ in function definition expressions.
-                                               
+\item Local functions within an outer function
+  must precede all other statements in body of the outer function.
 \end{itemize}
diff --git a/doc/source_return_3.tex b/doc/source_return_3.tex
new file mode 100644
index 00000000..e455ada8
--- /dev/null
+++ b/doc/source_return_3.tex
@@ -0,0 +1,14 @@
+\section*{Restrictions}
+
+\begin{itemize}
+\item Return statements are only allowed in bodies of functions.
+\item Return statements are not allowed in the bodies of while and for loops.
+\item There cannot be any newline character between
+$\textbf{\texttt{return}}$ and $\textit{expression}$ in return statements.
+\item There cannot be any newline character between
+  $(\ \textit{name}\ | \ \textbf{\texttt{(}}\ \textit{parameters}\ \textbf{\texttt{)}}\ )$
+                                               and
+$\texttt{\textbf{=>}}$ in function definition expressions.
+\item Local functions within an outer function
+  must precede all other statements in body of the outer function.
+\end{itemize}
diff --git a/doc/source_styleguide.tex b/doc/source_styleguide.tex
index 644a2818..bd330247 100644
--- a/doc/source_styleguide.tex
+++ b/doc/source_styleguide.tex
@@ -2,7 +2,7 @@
 
 \begin{document}
 	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-	\docheader{beta release}{Source}{Style Guide}
+	\docheader{Version 1.0}{Source}{Style Guide}
 	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 This is the style guide for the language Source,
@@ -35,6 +35,17 @@ function make_abs_adder(x) {
 Note the four spaces before \lstinline{return}, and then indentation of the \lstinline{if}
 statement four spaces to the right of the preceding \lstinline{function}.
 
+Four space indent also applies when individual lines get too long and
+need to be broken at convenient places. Example:
+\begin{lstlisting}
+function frac_sum(a, b) {
+    return (a > b) ? 0
+        : 1 / (a * (a + 2))
+            +
+            frac_sum(a + 4, b);
+}
+\end{lstlisting}
+
 \section*{Line Length}
   Lines should be truncated such that they do not require excessive horizontal scrolling.
   As a guide, it should be \emph{no more than 80 characters}.
@@ -104,10 +115,10 @@ const x = 1 + 1;
 const x=1+1;
 
 // good style
-return (x === 0) ? "zero" : "not zero";
+return x === 0 ? "zero" : "not zero";
 
 // bad style
-return (x === 0)?"zero":"not zero";
+return x === 0?"zero":"not zero";
 \end{lstlisting}
 	
 	Do not leave a space between unary operators and the variable involved.
@@ -120,43 +131,68 @@ const negative_x = -x;
 const negative_x = - x;
 \end{lstlisting}
 
-\subsection*{Function Definitions}
+\subsection*{Function Definition Expressions}
 
 Keep the parameters and the body expression of a function definition expression
 in one line, if they are short enough.
 
 If they are lengthy, use
-indentation. The indentation starts just below the first character of the \textit{parameter},
-or the open parenthesis, if there are multiple parameters. If the body expression does not
-fit in one line, use indentation so that the subsequent lines start after the blank character
-after the arrow.
+indentation. The indentation starts four characters after first character of
+the \textit{parameter}, if there is only one,
+or four characters after the open parenthesis,
+if there are multiple parameters. If the body expression does not
+fit in one line, use indentation following the first line of the body
+expression. 
 
 \begin{lstlisting}
 // good style
 function count_buttons(garment) {
     return accumulate((sleaves, total) => sleaves + total,
-                      0, 
-		      map(jacket
-		          => is_checkered(jacket)
-		             ? count_buttons(jacket)
-                             : 1,
-			  garment));
+        0, 
+        map(jacket =>
+            is_checkered(jacket)
+                ? count_buttons(jacket)
+                : 1,
+                garment));
 }
 
-// bad style
+// good style
+function count_buttons(garment) {
+    return accumulate(
+        (sleaves, total) =>
+            delicate_calculation(sleaves + total),
+        0,
+        map(jacket =>
+            is_checkered(jacket)
+                ? count_buttons(jacket)
+                : 1,
+            garment));
+}
+
+// bad style: too much indentation
 function count_buttons(garment) {
-    return accumulate((sleaves, total)
-                      =>
-                      sleaves + total,
+    return accumulate((sleaves, total) =>
+                      delicate_calculation(sleaves + total),
                       0, 
-		      map(jacket
-		          => is_checkered(jacket)
-		          ? count_buttons(jacket)
+		      map(jacket =>
+                          is_checkered(jacket)
+                          ? count_buttons(jacket)
                           : 1,
-			  garment));
+                          garment));
 }
 
-
+// no newline allowed between parameters and =>
+function count_buttons(garment) {
+    return accumulate(
+        (sleaves, total) 
+            => delicate_calculation(sleaves + total),
+        0,
+        map(jacket 
+            => is_checkered(jacket)
+                ? count_buttons(jacket)
+                : 1,
+            garment));
+}
 \end{lstlisting}
 
 
@@ -170,30 +206,31 @@ const aspect_ratio = landscape ? 4 / 3 : 3 / 4;
 
 // bad style
 const aspect_ratio = landscape
-                   ? 4 / 3
-                   : 3 / 4;
+    ? 4 / 3
+    : 3 / 4;
 \end{lstlisting}
 
 If the \textit{consequent-expression} or \textit{alternative-expression} are lengthy, use
-indentation. The indentation starts just below the \textit{predicate}.
+indentation. The indentation is as usual four characters longer
+than the indentation of the previous line.
 
 \begin{lstlisting}
 // good style
 function A(x,y) {
     return y === 0
-           ? 0
-           : x === 0
-             ? 2 * y
-             : y === 1
-               ? 2
-               : A(x - 1, A(x, y - 1));
-
-// bad style
+        ? 0
+        : x === 0
+            ? 2 * y
+            : y === 1
+                ? 2
+                : A(x - 1, A(x, y - 1));
+
+// bad style: line too long
 function A(x,y) {
     return y === 0 ? 0 : x === 0 ? 2 * y : y === 1 ? 2 : A(x - 1, A(x, y - 1));
 }
 
-// bad style
+// bad style: too much indentation
 function A(x,y) {
     return y === 0
                ? 0
@@ -275,12 +312,14 @@ if (x === 1) {
 
   Clean up \emph{all trailing whitespace} before submitting your program.
 
-\section*{Variables}
-\subsection*{Naming}
-When naming variables, use \emph{underscores} to separate words. Examples: \lstinline{my_variable}, \lstinline{x}, \lstinline{rcross_bb}.
+\section*{Names}
+\subsection*{Choice of names}
+When naming constants or variables,
+use \emph{underscores} to separate words.
+Examples: \lstinline{my_variable}, \lstinline{x}, \lstinline{rcross_bb}.
 
 \subsection*{Nesting}
-Do not use the same variable name for nested scope. Examples:
+Do not use the same name for nested scope. Examples:
 \begin{lstlisting}
 // bad program
 const x = 1;
diff --git a/src/interpreter-errors.ts b/src/interpreter-errors.ts
index 49c6b41a..56d20d2f 100644
--- a/src/interpreter-errors.ts
+++ b/src/interpreter-errors.ts
@@ -105,7 +105,7 @@ export class UndefinedVariable implements SourceError {
   }
 
   public explain() {
-    return `Undefined Variable ${this.name}`
+    return `Name ${this.name} not declared`
   }
 
   public elaborate() {
@@ -148,3 +148,41 @@ export class VariableRedeclaration implements SourceError {
     return 'TODO'
   }
 }
+
+export class ConstAssignment implements SourceError {
+  public type = ErrorType.RUNTIME
+  public severity = ErrorSeverity.ERROR
+  public location: es.SourceLocation
+
+  constructor(node: es.Node, private name: string) {
+    this.location = node.loc!
+  }
+
+  public explain() {
+    return `Cannot assign new value to constant ${this.name}`
+  }
+
+  public elaborate() {
+    return 'TODO'
+  }
+}
+
+export class EmptyForExpression implements SourceError {
+  public type = ErrorType.RUNTIME
+  public severity = ErrorSeverity.ERROR
+  public location: es.SourceLocation
+
+  constructor(node: es.Node, private missing: string[]) {
+    this.location = node.loc!
+  }
+
+  public explain() {
+    const exp = this.missing.length > 1 ? 'expressions': 'expression'
+    return `For statement cannot have empty ${this.missing.join(',')} ${exp}.`
+  }
+
+  public elaborate() {
+    return 'TODO'
+  }
+
+}
\ No newline at end of file
diff --git a/src/interpreter.ts b/src/interpreter.ts
index 67655742..2ad5e3b8 100644
--- a/src/interpreter.ts
+++ b/src/interpreter.ts
@@ -67,14 +67,22 @@ const handleError = (context: Context, error: SourceError) => {
   }
 }
 
-function defineVariable(context: Context, name: string, value: Value) {
+function defineVariable(context: Context, name: string, value: Value, constant=false) {
   const frame = context.runtime.frames[0]
 
   if (frame.environment.hasOwnProperty(name)) {
     handleError(context, new errors.VariableRedeclaration(context.runtime.nodes[0]!, name))
   }
 
-  frame.environment[name] = value
+  Object.defineProperty(
+    frame.environment,
+    name,
+    {
+      value,
+      writable: !constant,
+      enumerable: true
+    }
+  )
 
   return frame
 }
@@ -107,8 +115,13 @@ const setVariable = (context: Context, name: string, value: any) => {
   let frame: Frame | null = context.runtime.frames[0]
   while (frame) {
     if (frame.environment.hasOwnProperty(name)) {
-      frame.environment[name] = value
-      return
+      const descriptors = Object.getOwnPropertyDescriptors(frame.environment)
+      if(descriptors[name].writable) {
+        frame.environment[name] = value
+        return
+      }
+      const error = new errors.ConstAssignment(context.runtime.nodes[0]!, name)
+      handleError(context, error)
     } else {
       frame = frame.parent
     }
@@ -290,9 +303,10 @@ export const evaluators: { [nodeType: string]: Evaluator<es.Node> } = {
   },
   VariableDeclaration: function*(node: es.VariableDeclaration, context: Context) {
     const declaration = node.declarations[0]
+    const constant = (node.kind == "const")
     const id = declaration.id as es.Identifier
     const value = yield* evaluate(declaration.init!, context)
-    defineVariable(context, id.name, value)
+    defineVariable(context, id.name, value, constant)
     return undefined
   },
   ContinueStatement: function*(node: es.ContinueStatement, context: Context) {
@@ -302,9 +316,18 @@ export const evaluators: { [nodeType: string]: Evaluator<es.Node> } = {
     return new BreakValue()
   },
   ForStatement: function*(node: es.ForStatement, context: Context) {
+    // Check that all 3 expressions are not empty in a for loop
+    const missing_parts = ["init", "test", "update"].filter(
+      part => node[part] === null
+    );
+    if (missing_parts.length > 0) {
+      const error = new errors.EmptyForExpression(node, missing_parts);
+      handleError(context, error);
+    }
+
     // Create a new block scope for the loop variables
-    const frame = createBlockFrame(context, "forLoopFrame")
-    pushFrame(context, frame)
+    const loopFrame = createBlockFrame(context, "forLoopFrame")
+    pushFrame(context, loopFrame)
 
     if (node.init) {
       yield* evaluate(node.init, context)
@@ -315,9 +338,13 @@ export const evaluators: { [nodeType: string]: Evaluator<es.Node> } = {
       // create block context and shallow copy loop frame environment
       // see https://www.ecma-international.org/ecma-262/6.0/#sec-for-statement-runtime-semantics-labelledevaluation
       // and https://hacks.mozilla.org/2015/07/es6-in-depth-let-and-const/
-      const bound_env = { ...currentFrame(context).environment }
-      const frame = createBlockFrame(context, "forBlockFrame", bound_env)
+      // We copy this as a const to avoid ES6 funkiness when mutating loop vars
+      // https://github.com/source-academy/js-slang/issues/65#issuecomment-425618227
+      const frame = createBlockFrame(context, "forBlockFrame")
       pushFrame(context, frame)
+      for(let name in loopFrame.environment) {
+        defineVariable(context, name, loopFrame.environment[name], true)
+      }
 
       value = yield* evaluate(node.body, context)
 
@@ -387,7 +414,7 @@ export const evaluators: { [nodeType: string]: Evaluator<es.Node> } = {
     const id = node.id as es.Identifier
     // tslint:disable-next-line:no-any
     const closure = new Closure(node as any, currentFrame(context), context)
-    defineVariable(context, id.name, closure)
+    defineVariable(context, id.name, closure, true)
     return undefined
   },
   *IfStatement(node: es.IfStatement, context: Context) {
@@ -398,18 +425,11 @@ export const evaluators: { [nodeType: string]: Evaluator<es.Node> } = {
       handleError(context, error)
       return undefined
     }
-
-    // Create a new frame (block scoping)
-    const frame = createBlockFrame(context, "ifBlockFrame")
-    pushFrame(context, frame)
-
     if (test) {
       const result = yield* evaluate(node.consequent, context)
-      popFrame(context)
       return result
     } else if (node.alternate) {
       const result = yield* evaluate(node.alternate, context)
-      popFrame(context)
       return result
     } else {
       return undefined
@@ -441,13 +461,7 @@ export const evaluators: { [nodeType: string]: Evaluator<es.Node> } = {
       !(value instanceof BreakValue) &&
       !(value instanceof TailCallReturnValue)
     ) {
-      // Create a new frame (block scoping)
-      const frame = createBlockFrame(context, "whileBlockFrame")
-      pushFrame(context, frame)
-
       value = yield* evaluate(node.body, context)
-
-      popFrame(context)
     }
     if (value instanceof BreakValue) {
       return undefined
@@ -469,6 +483,11 @@ export const evaluators: { [nodeType: string]: Evaluator<es.Node> } = {
   },
   BlockStatement: function*(node: es.BlockStatement, context: Context) {
     let result: Value
+
+    // Create a new frame (block scoping)
+    const frame = createBlockFrame(context, "blockFrame")
+    pushFrame(context, frame)
+
     for (const statement of node.body) {
       result = yield* evaluate(statement, context)
       if (
@@ -479,6 +498,7 @@ export const evaluators: { [nodeType: string]: Evaluator<es.Node> } = {
         break
       }
     }
+    popFrame(context)
     return result
   },
   Program: function*(node: es.BlockStatement, context: Context) {


Test patch:
diff --git a/src/__tests__/__snapshots__/block_scoping.ts.snap b/src/__tests__/__snapshots__/block_scoping.ts.snap
index 47f6e8c8..c6a1330d 100644
--- a/src/__tests__/__snapshots__/block_scoping.ts.snap
+++ b/src/__tests__/__snapshots__/block_scoping.ts.snap
@@ -1,5 +1,15 @@
 // Jest Snapshot v1, https://goo.gl/fbAQLP
 
+exports[`Cannot leave blank expressions in for loops 1`] = `"Line 2: For statement cannot have empty init expression."`;
+
+exports[`Cannot leave blank expressions in for loops 2`] = `"Line 2: For statement cannot have empty test expression."`;
+
+exports[`Cannot leave blank expressions in for loops 3`] = `"Line 2: For statement cannot have empty update expression."`;
+
+exports[`Cannot leave blank expressions in for loops 4`] = `"Line 2: For statement cannot have empty init,test,update expressions."`;
+
+exports[`Cannot overwrite loop variables within a block 1`] = `"Line 5: Cannot assign new value to constant x"`;
+
 exports[`const uses block scoping instead of function scoping 1`] = `
 Object {
   "status": "finished",
@@ -21,14 +31,14 @@ Object {
 }
 `;
 
-exports[`interior of for loops don't affect loop variables 1`] = `
+exports[`let uses block scoping instead of function scoping 1`] = `
 Object {
   "status": "finished",
-  "value": 4,
+  "value": true,
 }
 `;
 
-exports[`let uses block scoping instead of function scoping 1`] = `
+exports[`standalone block statements 1`] = `
 Object {
   "status": "finished",
   "value": true,
diff --git a/src/__tests__/__snapshots__/index.ts.snap b/src/__tests__/__snapshots__/index.ts.snap
index 7964c125..f0924c2a 100644
--- a/src/__tests__/__snapshots__/index.ts.snap
+++ b/src/__tests__/__snapshots__/index.ts.snap
@@ -207,6 +207,8 @@ ArrowClosure {
 }
 `;
 
+exports[`Cannot overwrite consts even when assignment is allowed 1`] = `"Line 4: Cannot assign new value to constant constant"`;
+
 exports[`Empty code returns undefined 1`] = `
 Object {
   "status": "finished",
diff --git a/src/__tests__/__snapshots__/interpreter-errors.ts.snap b/src/__tests__/__snapshots__/interpreter-errors.ts.snap
new file mode 100644
index 00000000..1bf6b341
--- /dev/null
+++ b/src/__tests__/__snapshots__/interpreter-errors.ts.snap
@@ -0,0 +1,27 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`Undefined variable error is thrown 1`] = `
+Object {
+  "status": "error",
+}
+`;
+
+exports[`Undefined variable error is thrown 2`] = `
+Array [
+  UndefinedVariable {
+    "location": SourceLocation {
+      "end": Position {
+        "column": 16,
+        "line": 2,
+      },
+      "start": Position {
+        "column": 4,
+        "line": 2,
+      },
+    },
+    "name": "im_undefined",
+    "severity": "Error",
+    "type": "Runtime",
+  },
+]
+`;
diff --git a/src/__tests__/block_scoping.ts b/src/__tests__/block_scoping.ts
index e5f09768..d59aa942 100644
--- a/src/__tests__/block_scoping.ts
+++ b/src/__tests__/block_scoping.ts
@@ -1,15 +1,13 @@
 import { mockContext } from "../mocks/context";
-import { runInContext } from "../index";
+import { parseError, runInContext } from "../index";
 import { Finished } from "../types";
 
 // This is bad practice. Don't do this!
-test("const uses block scoping instead of function scoping", () => {
+test("standalone block statements", () => {
   const code = `
     function test(){
       const x = true;
-      if(true) {
-          const x = false;
-      } else {
+      {
           const x = false;
       }
       return x;
@@ -26,40 +24,43 @@ test("const uses block scoping instead of function scoping", () => {
 });
 
 // This is bad practice. Don't do this!
-test("let uses block scoping instead of function scoping", () => {
+test("const uses block scoping instead of function scoping", () => {
   const code = `
     function test(){
-      let x = true;
+      const x = true;
       if(true) {
-          let x = false;
+          const x = false;
       } else {
-          let x = false;
+          const x = false;
       }
       return x;
     }
     test();
   `;
-  const context = mockContext(3);
+  const context = mockContext();
   const promise = runInContext(code, context, { scheduler: "preemptive" });
   return promise.then(obj => {
-    expect(obj.status).toBe("finished");
     expect(obj).toMatchSnapshot();
+    expect(obj.status).toBe("finished");
     expect((obj as Finished).value).toBe(true);
   });
 });
 
 // This is bad practice. Don't do this!
-test("for loops use block scoping instead of function scoping", () => {
+test("let uses block scoping instead of function scoping", () => {
   const code = `
     function test(){
       let x = true;
-      for (let x = 1; x > 0; x = x - 1) {
+      if(true) {
+          let x = false;
+      } else {
+          let x = false;
       }
       return x;
     }
     test();
   `;
-  const context = mockContext(4);
+  const context = mockContext(3);
   const promise = runInContext(code, context, { scheduler: "preemptive" });
   return promise.then(obj => {
     expect(obj.status).toBe("finished");
@@ -69,15 +70,13 @@ test("for loops use block scoping instead of function scoping", () => {
 });
 
 // This is bad practice. Don't do this!
-test("interior of for loops don't affect loop variables", () => {
+test("for loops use block scoping instead of function scoping", () => {
   const code = `
     function test(){
-      let result = 0;
-      for (let x = 4; x > 0; x = x - 1) {
-        result = result + 1;
-        x = 0;
+      let x = true;
+      for (let x = 1; x > 0; x = x - 1) {
       }
-      return result;
+      return x;
     }
     test();
   `;
@@ -86,7 +85,7 @@ test("interior of for loops don't affect loop variables", () => {
   return promise.then(obj => {
     expect(obj.status).toBe("finished");
     expect(obj).toMatchSnapshot();
-    expect((obj as Finished).value).toBe(4);
+    expect((obj as Finished).value).toBe(true);
   });
 });
 
@@ -112,16 +111,16 @@ test("while loops use block scoping instead of function scoping", () => {
   });
 });
 
+//see https://www.ecma-international.org/ecma-262/6.0/#sec-for-statement-runtime-semantics-labelledevaluation
+//and https://hacks.mozilla.org/2015/07/es6-in-depth-let-and-const/
 test("for loop `let` variables are copied into the block scope", () => {
-  // see https://www.ecma-international.org/ecma-262/6.0/#sec-for-statement-runtime-semantics-labelledevaluation
-  // and https://hacks.mozilla.org/2015/07/es6-in-depth-let-and-const/
   const code = `
   function test(){
-        let z = [];
-        for (let x = 0; x < 2; x = x + 1) {
-          z[x] = () => x;
-        }
-        return z[1]();
+    let z = [];
+    for (let x = 0; x < 2; x = x + 1) {
+      z[x] = () => x;
+    }
+    return z[1]();
   }
   test();
   `;
@@ -129,7 +128,68 @@ test("for loop `let` variables are copied into the block scope", () => {
   const promise = runInContext(code, context, { scheduler: "preemptive" });
   return promise.then(obj => {
     expect(obj.status).toBe("finished");
-    expect(obj).toMatchSnapshot();
     expect((obj as Finished).value).toBe(1);
+    expect(obj).toMatchSnapshot();
   });
-})
\ No newline at end of file
+});
+
+test("Cannot overwrite loop variables within a block", () => {
+  const code = `
+  function test(){
+      let z = [];
+      for (let x = 0; x < 2; x = x + 1) {
+        x = 1;
+      }
+      return false;
+  }
+  test();
+  `;
+  const context = mockContext(3);
+  const promise = runInContext(code, context, { scheduler: "preemptive" });
+  return promise.then(obj => {
+    expect(obj.status).toBe("error");
+    const errors = parseError(context.errors);
+    expect(errors).toMatchSnapshot();
+  });
+});
+
+test("Cannot leave blank expressions in for loops", () => {
+  const code = [
+    `
+    for(; i < 3; i++) {
+      break;
+    }
+  `,
+    `
+    for(let i = 0; ; i++) {
+      break;
+    }
+  `,
+    `
+    for(let i = 0; i < 3;) {
+      break;
+    }
+  `,
+    `
+    for(;;) {
+      break;
+    }
+  `
+  ];
+  const scheduler = "preemptive";
+  const promises = code.map(c => {
+    const context = mockContext(3);
+    return runInContext(c, context, { scheduler }).then(obj => ({
+      context,
+      obj
+    }));
+  });
+  return Promise.all(promises).then(results => {
+    results.map(res => {
+      const { context, obj } = res;
+      expect(obj.status).toBe("error");
+      const errors = parseError(context.errors);
+      expect(errors).toMatchSnapshot();
+    });
+  });
+});
diff --git a/src/__tests__/index.ts b/src/__tests__/index.ts
index 6092f48a..e3f4bf28 100644
--- a/src/__tests__/index.ts
+++ b/src/__tests__/index.ts
@@ -96,6 +96,42 @@ test(
   30000
 )
 
+test("Cannot overwrite consts even when assignment is allowed", () => {
+  const code = `
+  function test(){
+    const constant = 3;
+    constant = 4;
+    return constant;
+  }
+  test();
+  `;
+  const context = mockContext(3);
+  const promise = runInContext(code, context, { scheduler: "preemptive" });
+  return promise.then(obj => {
+    expect(obj.status).toBe("error");
+    const errors = parseError(context.errors)
+    expect(errors).toMatchSnapshot()
+  });
+});
+
+
+test("Can overwrite lets when assignment is allowed", () => {
+  const code = `
+  function test(){
+    let variable = false;
+    variable = true;
+    return variable;
+  }
+  test();
+  `;
+  const context = mockContext(3);
+  const promise = runInContext(code, context, { scheduler: "preemptive" });
+  return promise.then(obj => {
+    expect(obj.status).toBe('finished')
+    expect((obj as Finished).value).toBe(true)
+  });
+});
+
 test(
   'Inifinite recursion with list args represents CallExpression well',
   () => {
diff --git a/src/__tests__/interpreter-errors.ts b/src/__tests__/interpreter-errors.ts
new file mode 100644
index 00000000..115bc94a
--- /dev/null
+++ b/src/__tests__/interpreter-errors.ts
@@ -0,0 +1,16 @@
+import { mockContext } from "../mocks/context";
+import { runInContext, parseError } from "../index";
+
+test("Undefined variable error is thrown", () => {
+  const code = `
+    im_undefined;
+  `
+  const context = mockContext()
+  const promise = runInContext(code, context, { scheduler: "preemptive" })
+  return promise.then(obj => {
+    expect(obj).toMatchSnapshot()
+    expect(obj.status).toBe("error")
+    expect(context.errors).toMatchSnapshot()
+    expect(parseError(context.errors)).toBe("Line 2: Name im_undefined not declared")
+  })
+})