How can I test a procedure to determine a procedure was the result

That is if I type:

+
#<procedure:+> 
is the value of the evaluation. If I then:
(check-expect '#<procedure:+> +)
it's bad syntax '#<'
or if I type (check-expect #<procedure:+> +)
it's the same.

Use the procedure? predicate.

> (procedure? +)
#t
> (procedure? "foo")
#f
> (check-pred procedure? +)
> (check-pred procedure? "foo")
--------------------
FAILURE
name:       check-pred
location:   stdin:?:?
params:     '(#<procedure:procedure?> "foo")
--------------------
3 Likes

Hmm... I claim that you're looking for

#lang htdp/asl

(check-expect + +)

... except that this reveals a larger problem: check-expect refuses to compare functions, and that's for a very good reason: in general, it's not possible to determine whether two functions are the same in a finite amount of time. For instance, it might be that the functions differ when called with 27719370427. How can racket figure that out? In general, you just have to try them all.

3 Likes

That makes sense to me. But, I'm really looking to see if + is a procedure, rather than if it 'equals' a given procedure.

Check out my answer above.

1 Like

Ah! @kablooey correctly guessed your requirement!

2 Likes