Basically I am trying to write a Common Lisp macro defined as:
(defmacro applyfunct (function arguments variables))
that applies the function given as the argument function, to the argument arguments (which is a list of arguments to apply the function to), that, when necessary, uses the variables given to it in the list of lists variables. So the return value when it is called with these arguments like this:
(applyfunct + (7 5) ((x 1) (y 2)))
would be 12, considering that 7+5=12, and the context variable x and y were not needed to apply the function to the arguments. However when it does require the context variables given:
(applyfunct (lambda (x y) (+ (* a x) (* y b)) (4 2) ((a 2) (b 4))))
it should use these variables if they are needed in the function given to evaluate to return 16, because:
(applyfunct (lambda (x y) (+ (* a x) (* y b)) (4 2) ((a 8) (b 1))))
; 4 2 8 4 2 1
; (+ (* 8 4) (* 2 1)) => 34
hopefully my comments here make clear what I'm trying to do. What I have so far is:
(defmacro applyfunct (function arguments variables)
(let ( ((car (first contents)) (cdar (first contents))
((car (second contents)) (cdar (second contents))
but I have no idea how to proceed...
(apply function arguments)
would only work for the first example call where the function is +, not the second function call with the lambda. Am I missing something here? Should I be using ` or #' somehow? Note: I am trying to program as functionally as possible (minimal to no side effects, for example, not using setq). I am also using the CLISP implementation of Common Lisp.
applyin the implementation andapplyan a typicalevalinterpreter. In the latter it would be normal to have an argument representing the environment. ' - Sylwester