Search code examples
racketprocedure

list of procedure not working? *Important


Working on an assignment right now (racket) and came across this problem.

> (define a '(even?))
> a
(even?)
> (first a)
even?
> (even? 2)
#t
> ((first a) 2)
. . application: not a procedure;
 expected a procedure that can be applied to arguments
  given: even?
  arguments.:

Why is this not working? Isn't ((first a) 2) equivalent to (even? 2) ??


Solution

  • '(even?) is equivalent to (quote (even?)) which returns a list with a symbol even? (not the function).

    If you want the code you're describing to work you need to have the first define look like (define a (list even?)) which is a list with the procedure even? in it.