small medium large xlarge

Back to: All Forums  PragPub
Headshot_pragsmall
05 Jun 2012, 13:59
Brian Tarbox (41 posts)

Another very good article on Scala. One thought I had was an alternative to the two method approach described at the end of the article. Another way to hide what amounts to the internal second argument is to use default values.

If the function definition is changed to: def factorial(n:BigInt, fact:BigInt = 1) : BigInt = … then the function can be called directly as one would expect e.g. factorial(5) and there is no need for the second function.

Of course this version leaves open the possibility of someone supplying a bad second argument but I’m suggesting it just to show an alternative.

Venkatsubramaniam_pragsmall
06 Jun 2012, 02:08
Venkat Subramaniam (99 posts)

Thanks Brian. The observation you made at the end is a significant limitation that ruled out this option.

Regards,

Venkat

You must be logged in to comment