Question

So I have this function:

(define (try try-block catch-block finally-block)
    ; Implements try/catch/finally like in most other languages
    )

for which I would like to create a "helper" macro that avoids the need for saying (lambda () ...) over and over again, kind of like set and setq:

(define-macro (tryq try-block catch-block finally-block)
    (try
        (lambda () (eval try-block))
        (lambda () (eval catch-block))
        (lambda () (eval finally-block))))

However, because lambda delays its arguments, the above program doesn't work -- the try-block inside eval is empty by the time it is evaluated, since it is inside a lambda.

How do I go about implementing this functionality correctly?

Was it helpful?

Solution

'expand' will do the job and you may also look into 'letex' which is a combination of 'let' and 'expand'.

OTHER TIPS

Never mind, I found it...

It turns out I need to use expand.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top