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

  • Home
  • SEARCH
  • 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 91897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:06:07+00:00 2026-05-10T23:06:07+00:00

Python, C++, Scheme, and others all let you define functions that take a variable

  • 0

Python, C++, Scheme, and others all let you define functions that take a variable number of arguments at the end of the argument list…

def function(a, b, *args):     #etc... 

…that can be called as followed:

function(1, 2) function(1, 2, 5, 6, 7, 8) 

etc… Are there any languages that allow you to do variadic functions with the argument list somewhere else? Something like this:

def function(int a, string... args, int theend) {...} 

With all of these valid:

function(1, 2) function(1, 'a', 3) function(1, 'b', 'c', 4) 

Also, what about optional arguments anywhere in the argument list?

def function(int a, int? b, int c, int... d) {}  function(1, 2) //a=1, c=2, b=undefined/null/something, d=[] function(1,2,3) //a=1, b=2, c=3,d=[] function(1,2,3,4,5) //a=1, b=2, c=3, d=[4,5] 
  • 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. 2026-05-10T23:06:08+00:00Added an answer on May 10, 2026 at 11:06 pm

    Future versions of Ruby (1.9 and up, Ruby 1.9 is scheduled to released at the end of January, 2009) can do this.

    It is however not always obvious which value gets bound to which parameter.

    This is what Ruby 1.9 accepts:

    0 or more mandatory arguments followed by 0 or more optional arguments followed by 0 or more mandatory arguments followed by rest arguments followed by 0 or more mandatory arguments.

    Example:

    def meth mand1, opt1 = :def1, o2 = :d2, *args, m2, m3   puts %w[mand1 opt1 o2 m2 args m3].inject('') { |s, arg|     s << '#{arg} = #{(eval arg).inspect}, '   }.gsub /, $/, '' end  meth :arg1, :a2, :a3 # => mand1 = :arg1, opt1 = :def1, o2 = :d2, m2 = :a2, args = [], m3 = :a3 meth :arg1, :a2, :a3, :a4 # => mand1 = :arg1, opt1 = :a2, o2 = :d2, m2 = :a3, args = [], m3 = :a4 meth :arg1, :a2, :a3, :a4, :a5 # => mand1 = :arg1, opt1 = :a2, o2 = :a3, m2 = :a4, args = [], m3 = :a5 meth :arg1, :a2, :a3, :a4, :a5, :a6 # => mand1 = :arg1, opt1 = :a2, o2 = :a3, m2 = :a5, args = [:a4], m3 = :a6 meth :arg1, :a2, :a3, :a4, :a5, :a6, :a7 # => mand1 = :arg1, opt1 = :a2, o2 = :a3, m2 = :a6, args = [:a4, :a5], m3 = :a7 

    As you can see, mandatory arguments are bound first, from both the left and the right. Then optional arguments get bound and if any arguments are left over, they get bundled up in an array and bound to the rest argument.

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

Sidebar

Ask A Question

Stats

  • Questions 70k
  • Answers 70k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer You could also store reverse links and just check that… May 11, 2026 at 12:53 pm
  • added an answer The 4 in %04d sets the total width of the… May 11, 2026 at 12:53 pm
  • added an answer Sure, it is possible! You would need to resolve the… May 11, 2026 at 12:53 pm

Related Questions

What is the idiomatic Python equivalent of this C/C++ code? void foo() { static
I'm a C/Python programmer in C++ land working with the STL for the first
I'm looking for Python code that removes C and C++ comments from a string.
I would like to call python script files from my c++ program. I am
I use Eclipse for Java, Python, C(++) and so on. I'm accustomed to Vim
I need to evaluate a Python expression from C++. This code seems to work:

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.