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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:51:50+00:00 2026-05-26T01:51:50+00:00

Is it possible to know if a default argument was supplied as an actual

  • 0

Is it possible to know if a default argument was supplied as an actual parameter value? In other words, assume that I defined a method:

def myMethod(x: Int = 1) = x + 1

Then is it possible to distinguish between these two calls (which return identical results because the parameter in the second method call has the same value as the default value in method definition) within the method body:

myMethod()
myMethod(1)

In other words, I want to know if there is technique to achieve an effect that is similar to -supplied-p feature in Common Lisp function definitions (see http://www.gigamonkeys.com/book/functions.html and http://www.psg.com/~dlamkins/sl/chapter21.html for details and more context).

  • 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-26T01:51:51+00:00Added an answer on May 26, 2026 at 1:51 am

    No, you can’t directly know this.

    Here’s an ugly workaround that relies on the fact that the default parameter can be a method call. It comes with many caveats, the biggest of which is that it is not thread-safe.

    private var usedDefault = false
    
    private def default = {
      usedDefault = true
      1
    }
    
    def myMethod(x: Int = default) = {
      if (usedDefault) {
        println("default")
      } else {
        println("supplied")
      }
      usedDefault = false
    }
    

    Another more practical workaround is this:

    def myMethod(): Unit = myMethod(1, usedDefault = true)
    def myMethod(x: Int): Unit = myMethod(x, usedDefault = false)
    
    private def myMethod(x: Int, usedDefault: Boolean) = {
      if (usedDefault) {
        println("default")
      } else {
        println("supplied")
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that it is possible to use settings to store some default values
Possible Duplicate: “Least Astonishment” in Python: The Mutable Default Argument def f(a, L=[]): L.append(a)
Is it possible to know if a stream/string contains an input that could match
Is it possible to know that a HTTP request is from Ajax?If yes, how?
I know its possible to accept a list of objects as a parameter thanks
Possible Duplicate: “Least Astonishment” in Python: The Mutable Default Argument Edit: This has nothing
I know it's possible to create a dynamically changable Default.png by creating a symbolic
Is it possible to reset a default layout from within a before_filter method in
I just want to know if is possible to get the permission that a
GWT-RPC requires that transfer objects to be serialized must have a default (zero-argument) constructor

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.