3 ms·
Others have answered already, but I remember this being confusing for me. And sometimes it still is. I think the crux of it comes to two things. The first is
by FPGAhacker 7y ago
Others have answered already, but I remember this being confusing for me. And sometimes it still is. I think the crux of it comes to two things. The first is that the text (f a b c) is evaluated as a function call with function 'f' receiving arguments a b and c. The second thing is that arguments are evaluated before they are passed into a function. So a b and c are evaluated first, and then given to 'f'. This is done recursively.
So (+ 1 2) first evaluates 1 and 2, which each evaluate to themselves and thus can't be simplified any further. They are then passed into '+'.
in (+ 1 (* 2 3)) the + is a function and the arguments are 1 and (* 2 3). 1 evaluates to itself. Evaluating (* 2 3) starts by evaluating 2 and 3, then applying them to '*' resulting in 6. So if we displayed an intermediate step, our form would now look like (+ 1 6), finally evaluating to 7.
To prevent the form (f a b c) from being treated as a function call, you can "quote" it by prefixing with a single quote (aka tick): '(f a b c). The evaluator now knows we intend that to just be data and not to evaluate it.
The exception to evaluating (f a b c) as a function call is if 'f' is a macro. In that case, the arguments a b and c are not evaluated and instead are passed into the macro as data.
Where this comes into play is if you want to programmatically change the code around before it's executed, and particularly where the arguments have side effects when they are evaluated (changing the state of something, like adding data to a database).