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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:56:36+00:00 2026-05-24T20:56:36+00:00

For example, I defined a method: def hello(String name) { println(Hello + name) }

  • 0

For example, I defined a method:

def hello(String name) {
    println("Hello " + name)
}

I want to the the name of argument in runtime:

def hello(String name) {
     println("The name of the parameter of this method is: " + getParamName())
     // getParamName() will be `name` here
}

And, I expect to get the passed name of the parameter:

def hello(String name) {
    println("Passed parameter name: " + getPassedName())
}

String user1 = "someone"
hello(user1)

It will print:

Passed parameter name:  user1

Notice, here is user1, the variable name!

I know this is difficult, since java/groovy/scala can’t do it. But I think it’s a very useful feature(especially for web-framework design). Is there a language can do it?

  • 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-24T20:56:36+00:00Added an answer on May 24, 2026 at 8:56 pm

    You can’t get the name of an argument in general because the argument may not be a named variable. Given this:

    def hello(String name) {
        println("Passed parameter name: " + getPassedName())
    }
    

    What would it output here:

    hello("a literal")
    hello("an " + "expression")
    

    Given that, there are some languages that let you access the raw AST of the passed argument. Macros in Lisp, Io, and Ioke all let you define functions that will take a chunk of unevaluated code as the argument, which you can then inspect.

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

Sidebar

Related Questions

I have this Perl script with many defined constants of configuration files. For example:
Let there be class Example defined as: class Example def initialize(test='hey') self.class.send(:define_method, :say_hello, lambda
How can I get the class that defined a method in Python? I'd want
I have a model defined as below: class Example(models.Model): user = models.ForeignKey(User, null=True) other
I have a complexType defined in targetNameSpace as say http://xyz.example.com and used in many
I have defined a default binding in my style. For example I have configured
The curses.ascii module has some nice functions defined, that allow for example to recognize
I wanted to check whether the variable is defined or not. For example, the
I don't get the abstractions and the terminology :-( For example, DirectoryInfo.FullName is defined
Take the following minimal example: import abc class FooClass(object): __metaclass__ = abc.ABCMeta @abc.abstractmethod def

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.