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 1086979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:52:51+00:00 2026-05-16T22:52:51+00:00

In the code snippet included below, I have a recursive function call, used to

  • 0

In the code snippet included below, I have a recursive function call, used to facilitate a retry if a network call fails (Amazon SimpleDB will occasionally return a 503 and require retry.)

When I try to compile, the Scala complains recursive method simpledb_update needs result type.

// sends data to SimpleDB. Retries if necessary
def simpledb_update(name: String, metadata: Map[String,String], attempt: Int) = {
 try {
  db(config("simpledb_db")) += (name, metadata)
 } catch {
  case e =>
   // if it fails, try again up to 5 times
  if(attempt < 6)
  {
   Thread.sleep(500)
   simpledb_update(name, metadata, attempt + 1)
   } else
     AUlog(name + ": SimpleDB Failed")
   }
 }

Why is this required on recursive functions? My thought is to just return a true/false boolean to satisfy the compiler… the following compiles fine.

// sends data to SimpleDB. Retries if necessary
 def simpledb_update(name: String, metadata: Map[String,String], attempt: Int): Boolean = {
 try {
  db(config("simpledb_db")) += (name, metadata)
  true
 } catch {
  case e =>
   // if it fails, try again up to 5 times
   if(attempt < 6)
   {
    Thread.sleep(500)
    simpledb_update(name, metadata, attempt + 1)
   } else
    AUlog(name + ": SimpleDB Failed")
    false
  }
}
  • 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-05-16T22:52:52+00:00Added an answer on May 16, 2026 at 10:52 pm

    As I understand it, recursive functions need a return type because the type inference algorithm is not powerful enough to determine return types for all recursive functions.

    However, you don’t need to make up a return type, you just need to declare the return type you were already using: Unit. Unit is a special type with only one element (). It’s also the type of most “statements” in Scala, and is the return type to declare for methods that don’t need to return anything, but are executed only for their side-effects (as yours is). You can either declare your method as returning unit as you would other types

    def simpledb_update(name: String, metadata: Map[String,String], attempt: Int):Unit = {
    

    More idiomatically Scala provides a special syntax for Unit-returning methods, just leave off the return type and the equals sign

    def simpledb_update(name: String, metadata: Map[String,String], attempt: Int){
    

    According to scala style guide you should prefer to use equal sign

    http://docs.scala-lang.org/style/declarations.html

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

Sidebar

Related Questions

I am writing a site using JSP. I have included a code snippet below.
I have a small snippet of code below that I'm running using PellesC .
Please look at the code snippet below - I have declared 3 functions (i.e.
Please see the code snippet below : #include <iostream> using namespace std; int main()
The Google Analytics setup instructions state: This tracking code snippet should be included in
This may be very obvious question, pardon me if so. I have below code
Greetings all, I have a code snippet as follows : class AppCtx { private:
EDIT In the initial posting's code snippet (see below) I was not properly sending
I am trying to add two Vectors below is the code snippet :- #include
This is the code snippet: #include <boost/utility.hpp> #include <boost/type_traits.hpp> #include <boost/type_traits/is_base_of.hpp> #include <boost/typeof/typeof.hpp> enum

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.