I have a question on the evaluation of Scheme, I just want to make sure I have a correct understanding on how procedures are evaluated.

So when the Scheme interpreter starts to evaluate a list, the first element is evaluated, this has to evaluate to a procedure or it is an error. If this procedure isn't a special form, then each element of the list is evaluated and then passed into the procedure as a parameter. If the procedure is a special form, then a different evaluation process is carried out e.g. for if, the first parameter is evaluated and then only one of two and three are evaluated. Also, atoms evaluated to either themselves, or a value they have been previously bound to.

Basically, are special forms needed to stop everything from being evaluated? Thanks

有帮助吗?

解决方案

Yes, special forms are needed to handle the special cases where you don't want everything to be evaluated. if is a good example:

(if (both-keys-turned) (launch-nuclear-missiles))

If all the parameters were evaluated, this would launch the missiles during that evaluation step, rather than waiting for if to test whether both keys were turned.

Or consider something like define:

(define var value)

If this evaluated var, it wouldn't be able to assign to it.

其他提示

The answer to your question is a qualified yes.

First off, your final sentence about the evaluation of atoms is incorrect in that it suggests that the meaning of an atom depends on whether or not it has been bound; this is not correct. Numbers, strings, booleans, and quoted forms are values and evaluate to themselves. Identifiers are not values, and evaluate to whatever they're bound to (or, if you think about evaluation using substitution, they're already gone by the time you get to them).

Second, your description of an evaluator processing a list is... reasonable, up to a point. It's a plausible way to build a simple interpreter, and a plausible basis for an evaluation semantics, but if you take a look at the insides of any mainstream Scheme interpreter (including Racket), what you'll see is something that looks like any other language--that is, a syntactic layer parses the input, then compilation happens, then the resulting program is run. I don't want you to leave with the impression that a Scheme interpreter actually processes syntax as lists.

Sorry for all the nit-picking. Maybe we should just say "yes" and get on with our lives.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top