source-academy / cs1101s

1 stars 0 forks source link

What is the difference between evaluating a function body with / without return keyword? #15

Open mrqorib opened 4 years ago

mrqorib commented 4 years ago

Question: What is the difference between evaluating a function body with / without return keyword? I'm a bit confused by when to add the return keyword in the function body block, and the difference it may create. Piazza: https://piazza.com/class/kas136yscf8605?cid=543

mrqorib commented 4 years ago

Answer: In Source, assignments are statements, not expressions. After the keyword return, an expression is expected. The full language description can be seen in https://source-academy.github.io/source/source_3.pdf . Regarding the difference between expressions and statements, page 2 of the document explains it