user618815
user618815

Reputation:

How to make it as procedure?

I have the scenario where a function returns an lambda form, and I want to apply the lambda form but failed. Example:

#lang racket

(define tes (lambda () `(lambda () 100)))
(tes)
((tes))

the result is:

'(lambda () 100)
. . procedure application: expected procedure, given: '(lambda () 100) (no arguments)

Then how can I make `(lambda () 100) as a procedure?

Upvotes: 1

Views: 237

Answers (1)

acfoltzer
acfoltzer

Reputation: 5618

If you remove the backquote from the inner lambda expression, it will work. Alternately, you could immediately unquote after the backquote, but that amounts to a noop:

> (define tes (lambda () (lambda () 100)))
> ((tes))
100
> (define tes (lambda () `,(lambda () 100)))
> ((tes))
100

Upvotes: 1

Related Questions