Consider this javascript:
function addX(n)
{
return 3 + n;
}
alert(addX(6)); //alerts 9
eval('var newFunc = ' + addX.toString().replace("3", "5") + ';');
alert(newFunc(10)); //alert 15
Please ignore the fact that it's of dubious use and methodology, dangerous, difficult to follow in a large codebase, and so on. It lets you modify the function, on the fly, based on input from the user. I don't have that demonstrated, but I just as easily could have.
I'm hoping you can show me how to do this in lisp. I've read a lot of tutorials, read a lot about macros, asked a broader question, tried a lot of things but ultimately have come up short.
I want to know how, in lisp, I can modify this function at runtime to instead add 5. Or whatever else the user might enter.
(define (addX n)
(+ 3 n))
I am not looking for currying! I know I can do this:
(define addXCurry
(lambda (x)
(lambda (n)
(+ x n))))
(define add5 (addXCurry 5))
(add5 10)
But this is creating a function-factory.
I'm using a simple example because I want to completely understand the hard way on something simple enough.
Edit Thank you all for your answers. I guess my big hangup around macros (as I understand them), is that I haven't seen one that completely separates the modification from the writing. The javascript example is simple - but you can do more complex re-writings based on user input.
The macros I've seen are all based around "compile-time" (or programmer-written-time I suppose). Like in C++ you can't have a dynamic template parameter - it has to be known at compile time.
(It seems) In lisp you can't fundamentally alter a procedure at run-time the way you can in javascript because you lost the source. You can eval and redefine it, but you can't iterate through the elements of the list (the list being the function definition), inspect each element and decide whether or not to change it. The exception seems to be the examples in Rainer's answer, which are shaky ground.