Append I used to connect two strings or lists, which can be used to concatenate two lists into a lambda expression:
> (Append (lambda (x)) ' ((add x 1))) (Lambda (x) (add x 1))
The first parameter of the Append is (lambda (x)) a list, with two elements, the second parameter is also a list, and the child element is also a list
After stitching, it becomes a complete lambda expression, accepting x as the parameter and being able to add 1 and return.
For further consideration, here add is written dead, if it will now (append ...) Into the body of a function, passing add as a function parameter to see what effect it will have.
> (Define (foo op) (Append (lambda (x)) (list op x 1)) (Lambda (OP) (Append (lambda (x)) (list op x 1)) ) > (foo ' Add 2) (lambda (x) (add x 1))
Attention:
1. Here is a list instead of ', because in actual use I found that the OP parameter transmission will be problematic, with list is good
2. The Foo function is actually a lambda expression, and the function body is (append ...) statement that the body of the function will return at run time (append ...) The results
That is (lambda (x) (add x 1))
The title of this article is a dynamic function, actually refers to the argument can be an operator, here (foo op) parameter op is can be ' Add, so foo is a dynamic function
To further improve it, Foo can accept a parameter p:
> (Define (Foo op p) (Append (lambda (x)) (list op p ' x))) (Lambda (OP p) (Append (lambda (x)) (list op p x)))
Append building Dynamic functions