optional-arguments

getopt does not parse optional arguments to parameters

In C, getopt_long does not parse the optional arguments to command line parameters parameters. When I run the program, the optional argument is not recognized like the example run below. $ ./respond --praise John Kudos to John $ ./respond --blame John You suck ! $ ./respond --blame You suck ! Here is the test code. #include <stdio.h...

Small Python optional arguments question

I have two functions: def f(a,b,c=g(b)): blabla def g(n): blabla c is an optional argument in function f. If the user does not specify its value, the program should compute g(b) and that would be the value of c. But the code does not compile - it says name 'b' is not defined. How to fix that? Someone suggested: def g(b): ...

how to use a function with a non-optional argument defined as the third

I'm using someone elses class and that person has defined a function with five arguments. in Sentry.php: function checkLogin($user = '',$pass = '',$group = 10,$goodRedirect = '',$badRedirect = '') If all five fields are filled in this leads to a login procedure. Now on the page where he explains how to use this there is a snippet wh...

What is the preferred design of a template function that requires a default parameter value?

I'm currently working on cleaning up an API full of function templates, and had a strong desire to write the following code. template <typename T, typename U, typename V> void doWork(const T& arg1, const U& arg2, V* optionalArg = 0); When I invoke this template, I would like to do so as follows. std::string text("hello"); doWork(100,...

Python optional parameters

Guys, I just started python recently and get confused with the optional parameters, say I have the program like this: class B: pass class A: def __init__(self, builds = B()): self.builds = builds If I create A twice b = A() c = A() and print their builds print b.builds print c.builds I found they are using the ex...

VB - How do I test if optional arguments are supplied or not?

How do I test if optional arguments are supplied or not? -- in VB6 / VBA Function func (Optional ByRef arg As Variant = Nothing) If arg Is Nothing Then <----- run-time error 424 "object required" MsgBox "NOT SENT" End If End Function ...

Optional argument cannot be erased?

I wanted to have a tail-recursive version of List.map, so I wrote my own. Here it is: let rec list_map f l ?(accum=[])= match l with head :: tail -> list_map f tail ~accum:(head :: accum) | [] -> accum;; Whenever I compile this function, I get: File "main.ml", line 69, characters 29-31: Warning X: this optional argument ...

LaTeX Optional Arguments

How do you create a command with optional arguments in LaTeX? Something like: \newcommand{\sec}[2][]{ \section*{#1 \ifsecondargument and #2 \fi} } } Then, I can call it like \sec{Hello} %Output: Hello \sec{Hello}{Hi} %Output: Hello and Hi ...

C# 4.0 optional out/ref arguments

Does C# 4.0 allow optional out or ref arguments? ...

Naming Optional Parameters in VSB

In Visual Basic, I have Functions with a lot of Optional arguments. I would like to be able to pass just a few of these Optional arguments to a Function without having to use numerous commas and spaces to get to the ones I want. Somewhere I saw a way to name params such as OptVar:=val, but that does not seem to work. Just wondering if th...

Overload Resolution and Optional Arguments in C# 4

I am working with some code that has seven overloads of a function TraceWrite: void TraceWrite(string Application, LogLevelENUM LogLevel, string Message, string Data = ""); void TraceWrite(string Application, LogLevelENUM LogLevel, string Message, bool LogToFileOnly, string Data = ""); void TraceWrite(string Application, LogLevelENUM L...

Is there a way to use default arguments that are the result of a function call in VB.NET?

I have a whole slew of database access functions which assume a particular connection string. Within my application I call myList = DB_MyTable.GetTableItems() and within GetTableItems() I have something like Dim connection As SqlConnection = MyDB.GetConnection So the connection string is in one place in the code, and I call a meth...

Can I default a function argument to the value of __FILE__ at the caller?

In C++, can I have a defaulted argument to a function which defaults to __PRETTY_FUNCTION__, __FILE__, and __LINE__ as defined at the point of the caller and not the point the defaults are supplied in a header file without using macros? ...

why is this optional method argument shared across different python objects?

Possible Duplicate: Least Astonishment in Python: The Mutable Default Argument can anyone explain me this? class Strange(object): def mutate(self, x=[]): x.append(1) return x obj = Strange() print obj.mutate() another_obj = Strange() print another_obj.mutate() >> [1] >> [1, 1] mutate() is called with...