Recently I am reading book SICP javascript. ( https://sourceacademy.org/sicpjs/1.1.4 )
And in this book ( chapter 1.1.4 ) I have a question about how function works.
function-expression(argument-expressions)
eg. square(2 + 5);
To evaluate a function application, the interpreter follows a procedure quite similar to the procedure for operator combinations described in section 1.1.3.
To evaluate a function application, do the following:
- Evaluate the subexpressions of the application, namely the function expression and the argument expressions.
- Apply the function that is the value of the function expression to the values of the argument expressions.
Where I have a question is number 2.
Before I read this book, when I use function, I just thought like pass the arguments to function.
So I have a confusion between Apply function to arguments or Apply arguments to function
This book said Apply function to arguments.
Can I get an answer why that is right and difference between them?
There is no difference. An application applies two things together. It's just math speak, or English peculiarities. Both phrases just mean that a function call is being made.
But also, the book is being more precise than what you were thinking. Instead of just saying "arguments", it talks about "arguments' values". Because, in f(x,y), or equally (f x y), what is the function being called? After all f or x are just names of variables.
So the book says, the value of the variable f is used as the function, which is called with the value of the variable x, and of y, as the argument values.
Because there are other call disciplines, e.g. in "call by name" the variables themselves are passed in as the arguments. But Scheme (as originally used by the book) is "call by value".