It's not possible to create a function where the formal parameters and body are given as run-time values (S-expressions) without using eval
.
But based on your answer to Greg's comment, you can change your defmethod
macro to avoid this issue. Your current approach takes the variables and body expression (program terms), converts them to run-time values, then wants to reinterpret them as program terms. Instead, you should just combine the program terms into a lambda
-expression in the macro, which you can then pass as a value to the helper function:
(define-syntax-rule (defmethod name ((var predicate) ...) body)
(add-to-generic name
(list predicate ...)
(lambda (var ...) body)))
If you wanted to keep the variable names around (eg for error messages), you can also quote them, but separate from the lambda
-expression:
(define-syntax-rule (defmethod name ((var predicate) ...) body)
(add-to-generic name
(list predicate ...)
'(var ...) ;; for errors, debugging, etc
(lambda (var ...) body)))