XMPP JavaScript Library

Factorial program in erlang using fold, recursion and guards

Erlang, Sachin Puri, 2016-11-19 00:47:12

Using Recursion

This is an example program to show how can we make use of recursion in erlang to write a factorial program.


fact(0)-> 1;
fact(N)-> N * fact(N-1).

Using Recursion (With Guard)

This is an example program to show how can we make use of guard with recursion in erlang to write a factorial program.


fact(N) when N == 0 -> 1;
fact(N) when N > 0 -> N * fact(N-1).

Using Fold

This is an example program to show how can we make use of fold in erlang to write a factorial program.


lists:foldl(fun(A,B)-> A*B end , 1, [1,2,3,4,5,6,7,8,9,10]).

 

Add Your Comment
   
    Yes! I want to receive all comments by email

  by payday consolidation loans on 25-Jun-2019 05:11 pm
Thanks for the article. My partner and i have continually seen that a majority of people are wanting to lose weight simply because wish to show up slim and attractive. Nonetheless, they do not usually realize that there are other benefits so that you can losing weight as well. Doctors claim that over weight people have problems with a variety of health conditions that can be perfectely attributed to the excess weight. The great news is that people who sadly are overweight along with suffering from different diseases can help to eliminate the severity of their particular illnesses by losing weight. You’ll be able to see a gradual but notable improvement with health if even a moderate amount of weight loss is accomplished. payday consolidation loans
  • Reply
  •  0 Like
  •  0 Dislike
  • Report
  by QQ882my Online Slot on 19-Jun-2019 06:21 am
Play online slot games here at the most interesting gambling site online slot Malaysia https://tessgit.mit.edu/QQ882my and get more winnings.
  • Reply
  •  0 Like
  •  0 Dislike
  • Report
  by QQ882my Online Slot on 19-Jun-2019 06:20 am
Play online slot games here at the most interesting gambling site online slot Malaysia https://tessgit.mit.edu/QQ882my and get more winnings.
  • Reply
  •  0 Like
  •  0 Dislike
  • Report
  by bangladesh cloth factory on 18-Jun-2019 04:36 pm
Great survey. I'm sure you're getting a great response. bangladesh cloth factory
  • Reply
  •  0 Like
  •  0 Dislike
  • Report
  by go now professional link building services on 18-Jun-2019 04:30 pm
Marketing1on1.com has provided industry-standard web hosting and related services to hundreds of thousands of customers across the globe. Your website deserves the quality and care that we can provide, using cutting-edge tactics and strategies through our SEO strategy services. go now professional link building services
  • Reply
  •  0 Like
  •  0 Dislike
  • Report
  by view at kismis on 17-Jun-2019 07:25 pm
away many folks who may have been lovers of your website. view at kismis
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by buy dumps on 17-Jun-2019 07:25 pm
I do believe all of the ideas you have introduced on your post. They’re really convincing and will definitely work. Nonetheless, the posts are very quick for beginners. Could you please lengthen them a bit from next time? Thank you for the post. buy dumps
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by High Fiber Foods on 15-Jun-2019 01:02 pm
I wish more writers of this sort of substance would take the time you did to explore and compose so well. I am exceptionally awed with your vision and knowledge. High Fiber Foods
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by Turnips on 15-Jun-2019 12:56 pm
I’m happy I located this blog! From time to time, students want to cognitive the keys of productive literary essays composing. Your first-class knowledge about this good post can become a proper basis for such people. nice one Turnips
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by Erythritol on 15-Jun-2019 12:46 pm
Type your comment...This is a good post. This post gives truly quality information. I’m definitely going to look into it. Really very useful tips are provided here. Thank you so much. Keep up the good works Erythritol
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by free steam wallet codes on 14-Jun-2019 01:24 pm
I like what you guys are up too. Such intelligent work and reporting! Keep up the excellent works guys I’ve incorporated you guys to my blogroll. I think it will improve the value of my web site free steam wallet codes
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by 안전공원사이트 on 13-Jun-2019 07:35 pm
Look this info So i am pleased to take that I have a very good imprint 안전공원사이트
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by voyance cartomancie on 13-Jun-2019 03:25 pm
Resources similar to the one a person pointed out here may well be very useful to me! I will set up a link to this web page on my small blog. I’m particular my personal site visitors will discover which really helpful. voyance cartomancie
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by does barkbox charge monthly on 13-Jun-2019 03:24 pm
Receive a Monthly Box of Dog Goodies starting month! Don't delay, get one today! does barkbox charge monthly
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by Motivation for Life on 12-Jun-2019 04:31 pm
I like what you guys are up too. Such clever work and reporting! Carry on the excellent works guys I’ve incorporated you guys to my blogroll. I think it’ll improve the value of my website . Motivation for Life
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by เช่ากระเป๋าเดินทาง on 12-Jun-2019 04:30 pm
Thanks for your content. One other thing is when you are advertising your property by yourself, one of the problems you need to be cognizant of upfront is when to deal with home inspection reports. As a FSBO supplier, the key to successfully shifting your property and also saving money upon real estate agent commissions is know-how. The more you already know, the smoother your home sales effort will likely be. One area that this is particularly crucial is assessments. เช่ากระเป๋าเดินทาง
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by QQPlaywin on 12-Jun-2019 03:46 pm
Oh my goodness! an amazing article dude. Thanks a ton Nonetheless I will be experiencing problem with ur rss . Do not know why Not able to join it. Can there be everyone acquiring identical rss issue? Anybody who knows kindly respond. Thnkx QQPlaywin
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by 755蜂巢皮秒雷射 on 12-Jun-2019 03:46 pm
Hi, you used to write excellent articles, but the last several posts have been kinda boring… I miss your tremendous posts. Past few posts are just a little out of track! 755蜂巢皮秒雷射
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by Natto on 11-Jun-2019 11:17 pm
I want you to thank for your time of this wonderful read!!! I definately enjoy every little bit of it and I have you bookmarked to check out new stuff of your blog a must read blog! Natto
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by forskolin research on 11-Jun-2019 08:51 pm
Are you find weight loss supplement? So used for Our product forskolin pills. Read more forskolin research
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by 15minute title loans on 11-Jun-2019 08:51 pm
Auto loans are the most popular type of car financing when purchasing a new car. Check Our Website 15minute title loans
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by monthly listeners on 08-Jun-2019 02:09 pm
Oh my goodness! an incredible post dude. Thank you Nonetheless I’m experiencing issue with ur rss . Do not know why Struggling to subscribe to it. Possibly there is anyone getting identical rss difficulty? Anybody who knows kindly respond. Thnkx monthly listeners
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by necklace and earring sets online on 08-Jun-2019 02:08 pm
Will not simply turn a very important thing such as duty money back guarantee towards a bad thing enjoy i . d break-ins.
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by πλαστικος χειρουργος κυπρος on 07-Jun-2019 09:36 pm
Thanks for another excellent article. The place else could anyone get that type of information in such a perfect means of writing? I have a presentation next week, and I’m at the search for such info. πλαστικος χειρουργος κυπρος
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by Villas for sale In Protaras on 07-Jun-2019 09:36 pm
you have a very excellent blog here! do you wish to have invite posts on my own weblog? Villas for sale In Protaras
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by marketing1on1: Online Internet Marketing Services, Website Marketing Company on 05-Jun-2019 02:31 am
Our SEO content services naturally build your rankings and visibility in search engine results marketing1on1: Online Internet Marketing Services, Website Marketing Company
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by consolidate payday loans on 05-Jun-2019 02:31 am
Good day! I know this is kind of off topic but I was wondering which blog platform are you using for this website? I’m getting sick and tired of WordPress because I’ve had issues with hackers and I’m looking at options for another platform. I would be fantastic if you could point me in the direction of a good platform. consolidate payday loans
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by mold stain removers on 30-May-2019 01:05 pm
I think other website owners should take this website as an model, very clean and superb user genial design and style . mold stain removers
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by aviation helmets on 30-May-2019 01:04 pm
The actual challenge to become is normally you can actually SOLE check out that level of your tax discount over the internet by looking at your RATES web-site. aviation helmets
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by how to sell house fast on 25-May-2019 04:07 pm
The thing i like about your blog is that you always post direct to the point info. how to sell house fast
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by Chat Flirt England on 24-May-2019 04:54 pm
dancing is my passion and and i enjoy being enrolled in a dance class to improve my skills“ Chat Flirt England
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by buy cannabis canada on 24-May-2019 04:54 pm
Harry Potter is the best, i really like Daniel Radcliffe because he acts very well. buy cannabis canada
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by Guest posting services on 23-May-2019 03:54 pm
Type your comment...Our new Orders Tracking interface allows you to track all your guest posts from a central location, see the exact processing stage of each article, along with all the necessary information to keep you informed. Guest posting services
  • Reply
  •  1 Like
  •  1 Dislike
  • Report