Append building Dynamic functions

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.