Questions tagged [optional-arguments]

An optional argument is an argument which can be omitted, eventually being replaced by a default value, where an argument is an actual value passed to a function, procedure, or command line program.

223 questions
4
votes
2 answers

How to deal with ellipsis (...) in the presence of optional arguments?

I have a problem with ellipsis when I use optional arguments in my function definition. To clarify, I define following functions: func1 <- function (x) (x-2)^2 func3 <- function (fun, arg.curve.user){ arg.curve.user$expr <- substitute(func1) …
Ehsan Masoudi
  • 712
  • 10
  • 19
4
votes
3 answers

Using optional arguments

I have a method with 2 optional parameters. public IList GetComputers(Brand? brand = null, int? ramSizeInGB = null) { return new IList(); } I'm now trying to use this method elsewhere where I do not want to specify the Brand…
litterbugkid
  • 3,534
  • 7
  • 36
  • 54
4
votes
5 answers

Non-Standard Optional Argument Defaults

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…
ooboo
  • 16,259
  • 13
  • 37
  • 32
4
votes
8 answers

php function arguments

I don't know how or where I got this idea in my head but for some reason I thought this was possible. Obviously after testing it doesn't work, but is there a way to make it work? I want to set $value2 without having to enter anything at all for…
Clint C.
  • 678
  • 13
  • 31
3
votes
1 answer

How to call method with optional parameter list in JSF2 / EL 2.2

any idea how (if even possible) to call java method with optional parameters from JSF page? Iam using Java 7,JSF 2.1, EL 2.2 (Glassfish 3.1.2). Thanks in advance... I got this exception javax.el.ELException: /example.xhtml: wrong number of…
Wooff
  • 1,091
  • 12
  • 23
3
votes
1 answer

Matlab Arbitrary Output Argument Combination Disgarding

Is it possible to check whether the Matlab function output argument N is disgarded by its caller (~ given in call) or not provided one of its N+K, K>1, is defined, that is when nargout > N. For instance, given function [x,y] = f() ...; end we…
Nordlöw
  • 11,838
  • 10
  • 52
  • 99
3
votes
1 answer

Passing optional path arguments to ant

I have an ant task that uses an apply task to run a script on a group of files. I have a directory structure resultant of something like this: mkdir -p a/{b,c,d,e}/f Normally (if I pass no arguments), I would like ant to run on all fs. That is, if I…
yarian
  • 5,922
  • 3
  • 34
  • 48
3
votes
1 answer

How to code optional arguments for a custom function that wraps ggplot()?

I have a general question that I couldn't find a satisfactory answer for. I'm building a set of visualization functions, and I want to let the user have flexibility when using them. For example, I'd like to keep it optional whether errorbars should…
Emman
  • 3,695
  • 2
  • 20
  • 44
3
votes
1 answer

Common Lisp: How to pass a keyword argument iff it has been passed to me

Time and again I find myself in the situation that a function A needs to call function B with or without keyword arguments, depending on whether such keyword arguments have been given to function A. Maybe a silly MWE is easier to follow: let's ask a…
Dominik Mokriš
  • 1,118
  • 1
  • 8
  • 29
3
votes
2 answers

Object is possibly 'undefined'.ts(2532) with optional arguments

I have this code: export default class MyRandomClass { private posFloat32Array?: Float32Array; private otherArgument?: number; constructor(params:MyRandomClass = {} as MyRandomClass) { const { posFloat32Array, otherArgument, …
rustyBucketBay
  • 4,320
  • 3
  • 17
  • 47
3
votes
4 answers

Is there a way to force mutually exclusive function parameters in python?

Consider: def foobar(*, foo, bar): if foo: print('foo', end="") if bar: print('bar', end="") if foo and bar: print('No bueno', end='') # I want this to be impossible if not foo and not bar: print('No…
3
votes
1 answer

Test function for checking an optional argument

Related to my previous question, I have tried to make a function present() for checking the presence of an optional argument. However, the following code proc present( x ) { return x.type != void; } proc test( a: ?T = _void ) { writeln(); …
roygvib
  • 7,218
  • 2
  • 19
  • 36
3
votes
0 answers

Prevent evaluation of optional arguments when generating Sphinx documentation

Suppose I have the following Python file and am trying to document it with Sphinx """The foo module. """ def foo(s): """The foo function. :param s: a string """ return s + "!" def bar(x, y=foo('Baz')): """The bar function. …
edwargix
  • 31
  • 3
3
votes
2 answers

Requiring a command line argument if an optional argument is provided

I'm trying to write a script in which a user can choose from three different options: python foo.py python foo.py -a python foo.py -b address_arg data_arg If the user chooses the last option I need them to provide two additional arguments for…
3
votes
2 answers

access decorator arguments inside the decorators wrapper function

im trying to access my decorators arguments inside the wrapper function with no luck. what i have is: def my_decorator(arg1=False, arg2=None): def decorator(method): @functools.wraps(method) def wrapper(method, *args,…
aschmid00
  • 7,038
  • 2
  • 47
  • 66