Introduction to a functional programming language-cat on the. NET platform

Source: Internet
Author: User

I used to write commands like Java and C #.Programming LanguageOfProgramAre you interested in trying the functional programming language on this. NET platform?
Cat language is a stack-based functional language that can run on. NET and mono platforms. Its Interpreter is written in C,
TotalCodeThe amount is about 15 K. You can try to analyze the code. Maybe you will have a deep understanding of the principles of functional programming.
To put it bluntly, describe the function language's Fibonacci first.
Define fib (N)
{N 1 <= [N] [n 1-fib N 2-fib +] If}
Is this tianshu?
Calm down and analyze it carefully:
Stack-based expressions should be post-order expressions, which are analyzed step by step:
N 1 <= Limit n <= 1
N 1 <= [N] returns n when limit n <= 1
N 1 <= [N] [n 1-fib N 2-fib +] If, can be interpreted:
If n <= 1
Returns n
Else
Returns n 1-fib N 2-fib +
N 1-fib N 2-fib + is fib (n-1) + fib (n-2 ).
Well, the entire expression is converted to an imperative programming language like this:

Int FIB ( Int N)
{
If (N <= 1 )
Return   1 ;
Else
Return FIB (n -   1 ) + FIB (n -   2 );
}

The difference between one line of code and four lines of code is so big.
Please try it at http://code.google.com/p/cat-language /.
The last one is my:

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.