They are syntactically different but semantically equivalent.
This is a syntactic sugar? Yes, the let expression is just syntactic sugar for anonymous function. Is this correct all the time?
They are syntactically different but semantically equivalent.
This is a syntactic sugar? Yes, the let expression is just syntactic sugar for anonymous function. Is this correct all the time?
Suppose you wanted to fix a bug in your code. It’s tempting to not exit the toplevel, edit the file, and re-issue the #use directive into the same toplevel session. Resist that temptation. The “stale code” that was loaded from an earlier #use directive in the same session can cause surprising things to happen—surprising when you’re first learning the language, anyway. So always exit the toplevel before re-using a file.
This behavior, along with #use in the REPL can lead to confusing effects
Suppose I have the following program:
ocaml
let x = 8;;
let y = 2;;
I load that into the REPL with #use. Now, I decide to change my program, and I delete a line, giving this:
ocaml
let x = 8;;
I load that into the REPL without restarting the REPL. What goes wrong?
Hint: what is the value of y?
The answer: y is still 2, which is not what you want, right?
Note how OCaml is flexible about whether you write the parentheses or not, and whether you write whitespace or not. One of the challenges of first learning OCaml can be figuring out when parentheses are actually required. So if you find yourself having problems with syntax errors, one strategy is to try adding some parentheses. The preferred style, though, is usually to omit parentheses when they are not needed. So, increment 21 is better than increment(21).
Is the parentheses are syntactic sugar?
A good programmer has to learn the principles behind programming that transcend the specifics of any specific language.
The "programming languages" courses in coursera presented by Dan Grossman have the same goals as this.