Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8360527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:29:22+00:00 2026-06-09T11:29:22+00:00

I stumbed on the link below which shows how funny scala messages can be

  • 0

I stumbed on the link below which shows how funny scala messages can be 😉

Scala REPL “She’s gone rogue” error message

When i tried this example, it hung forever.what is happening here?

Is this a known bug?Is it some kind of gotcha?

Welcome to Scala version 2.9.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_29
).
Type in expressions to have them evaluated.
Type :help for more information.

scala> def factorial(n: Int):Int = {
     |   if (n == 1) n    // forgot 'return' here
     |   factorial(n - 1)
     | }
factorial: (n: Int)Int

scala> factorial(10)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T11:29:24+00:00Added an answer on June 9, 2026 at 11:29 am

    The problem is exactly what is indicated in the code, return is missing. The recursion never terminates.

    factorial(n - 1) is not connected to the if statement in any way. This means, that it executes unconditionally. factorial() wil always call itself.

    Adding a base case (i.e. where the recursion stops):

    def factorial(n: Int):Int = {
         |   if (n == 1) return n
         |   factorial(n - 1)
         | }
    

    This would work as well:

    def factorial(n: Int):Int = {
         |   if (n == 1) n
         |   else factorial(n - 1)
         | }
    

    This will actually produce the factorial of n (the others return 1):

    def factorial(n: Int):Int = {
         |   if (n <= 1) 1
         |   else n * factorial(n - 1)
         | }
    

    Note that this works for the case n = 0 correctly as well. It still accepts negative numbers, however.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some very simple code below that I can't get to validate on
I'm really stumped by this one! The StackFrame object ( MSDN Link ) has
I stumbled upon a question (in a test) about which aggregate functions are applicable
I stumbled upon this add-on which Ajaxifies parts of its target website. https://addons.mozilla.org/en-US/firefox/addon/51789 I
Stumped...my menu shows up about 25% of the time in IE7. It appears to
Apologies for this basic question, but I am noob stumped. The below code works
I have created a google map located at: http://calwestcultural.com/sgs/example_map.html I am trying to link
I am stumped as to how I can extract the href attribute from the
I am trying to link the checkbox and listview together, and then use the
update- sorry folks, i should have provided the link to the website where i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.