1
votes

In 4.1.3 Evaluator Data Structures of SICP, it states:

That the user's programs are the evaluator's data need not be a source of confusion. In fact, it is sometimes convenient to ignore this distinction, and to give the user the ability to explicitly evaluate a data object as a Lisp expression, by making eval available for use in programs. Many Lisp dialects provide a primitive eval procedure that takes as arguments an expression and an environment and evaluates the expression relative to the environment.

Then experiment with

Chez Scheme Version 9.5
Copyright 1984-2017 Cisco Systems, Inc.

> (define a 5)
> (define b 6)
> (eval '(* a b))
30

I think the result not make sense, since it does both eval and apply.

As I learned from the proceeding contents, I predict the result should be

> (eval '(* a b))
  '(* (5 6))

Then apply * to list-of-values (5 6).

Eval produce value of arguments and procedures to be applied rather than a final result.

Am I wrong with the understanding of eval?

1
Application is part of evaluation. (* a b) by itself evaluates to 30, not (* 5 6).chepner
evaling an expression evaluates it completely.molbdnilo
To get (* 2 3): (eval ''(* 2 3)). Notice the double quoting.Flux

1 Answers

3
votes

Basically what happens with (eval '(* a b)) under the hood is as you describe. Since * is not a special form or macro it evaluates it to the procedure object, then it evaluates a and b and it then applies the procedure it got from evaluating * with the list of evaluated arguments. It does not stop half way so you get the full evaluation.

Also know that * is a variable. The procedure behind it you can see by evaluating *by itself. It would not have shown *.