Clojure language 10: FN object

Source: Internet
Author: User

(FN...) can be used to create anonymous functions, such:

User => (FN [x] (+ 2 X) # <user $ eval328 $ FN _ 329 user $ eval328 $ FN _ 329 @ f41393>

Accept a parameter X and add 2. The above call defines a function using FN, but it is not executed. If you want to execute it immediately, you can add brackets and parameters:

User => (FN [x] (+ 2 X) 5) 7

But in more cases, we want to define the function first and use it repeatedly. You can combine the following Def:

User => (def f (FN [x] (+ 2 X) # 'user/Fuser => (F 1) 3 user => (F 6) 8

In this way, the F function is defined and then called twice.

FN also supports variable parameter overloading, and actually implements the FN interface. For more information, see the official documentation:

Http://clojure.org/special_forms#fn

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.