For the expression
(define x (length (range 3000)))
I think it is evaluated to
(define x 3000)
For the expression
(define (f x) (length (range 3000)))
Does it evaluate to the following as well?
(define (f x) 3000)
No, they evaluate to two different procedures, with different bodies. A completely different matter is that when executed, they both will return the same value, namely 3000
, ignoring the parameter in both cases. To be clear, the first expression binds f
to a lambda
(this is how define
expands a procedure definition under the hood):
(define f
(lambda (x) (length (range 3000))))
The second expression also binds f
to a lambda
, but it's a different one:
(define f
(lambda (x) 3000))
Either one will return 3000
when invoked:
(f 42)
=> 3000
But the first one will do more work, it has to create a range
and calculate its length
, whereas the second one simply returns 3000
. Regarding your first example - in the end x
will have the same value, and it won't matter how you calculated it. But for the second example, the two f
s are different objects, even though the values they calculate are the same.