munificent / craftinginterpreters

Repository for the book "Crafting Interpreters"
http://www.craftinginterpreters.com/
Other
8.75k stars 1.03k forks source link

Typo in the Code Snippet #1012

Closed ali-p-q closed 2 years ago

ali-p-q commented 2 years ago

Section 3.8.1 of the book, titled Closures, has this code snippet:

fun addPair(a, b) {
  return a + b;
}

fun identity(a) {
  return a;
}

print identity(addPair)(1, 2); // Prints "3".

I believe the last line should have been typed:

print identity(addPair(1, 2)); // Prints "3".

Source code file/line: https://github.com/munificent/craftinginterpreters/blame/master/book/the-lox-language.md#L631

Runrioter commented 2 years ago

addPair is a first-class function.

kandersen commented 2 years ago

Duplicate of #852 . Thought I had explained this once already :)

munificent commented 2 years ago

Yes, as #852 states, this code is correct (though a little unusual).