Reputation: 11
(define rearrange
(λ ignore
(define (proc1 x y) (+ x y))
(foldr (λ (x y) (if (list? x) (append (rearrange x y) y)
(if (procedure? x)
(append y (list x)) (cons x y)))) empty '(a proc1 b))))
why isn't x
being recognized as a procedure even though I defined it as such right before the call to foldr?
Upvotes: 0
Views: 57
Reputation: 43842
Nope. In that list, and
is not a procedure. It is a symbol.
This is due to how quoting works. The expression '(a b c)
is effectively the same as (list 'a 'b 'c)
, so and
is literally evaluated as the symbol, 'and
.
Either explicitly use the list
function to make your list, or use quasiquoting. Either of these expressions should produce what you want:
(list 'a and 'b)
`(a ,and b)
Upvotes: 1