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
7
votes
3 answers

Typescript: Optional function arguments cause problems in function body

I am new to TypeScript and have a little problem with an optional argument in a function. I got the following error in Visual Studio Code for the query argument (see screen shot). I really don't understand this error, because I defined the type as…
FunkyFabe
  • 149
  • 2
  • 8
7
votes
1 answer

Can we avoid creating a local variable if an optional argument is not PRESENT?

I am having a problem with the PRESENT statement with Fortran 95. Currently I am using Silverfrost's Plato and their FTN95 compiler (in "Release Win32" mode). What I wanted to do is to create a subroutine SUB(a,b), where b is an optional variable.…
gilbertohasnofb
  • 1,984
  • 16
  • 28
7
votes
1 answer

xUnit test engine's InlineDataAttribute + optional method parameters

Is it possible to make xUnit test work when you don't specify optional parameter values in InlineDataAttribute? Example: [Theory] [InlineData(1, true)] // works [InlineData(2)] // error void Test(int num, bool fast=true){}
Anri
  • 6,175
  • 3
  • 37
  • 61
6
votes
3 answers

Creating a C# Nullable Int32 within Python (using Python.NET) to call a C# method with an optional int argument

I'm using Python.NET to load a C# Assembly to call C# code from Python. This works pretty cleanly, however I am having an issue calling a method that looks like this: A method within Our.Namespace.Proj.MyRepo: OutputObject GetData(string user, int…
skulz00
  • 769
  • 8
  • 18
5
votes
3 answers

Is there any way to define a Python function with leading optional arguments?

As we know, optional arguments must be at the end of the arguments list, like below: def func(arg1, arg2, ..., argN=default) I saw some exceptions in the PyTorch package. For example, we can find this issue in torch.randint. As it is shown, it has a…
javadr
  • 310
  • 2
  • 12
5
votes
1 answer

Can I define both function's argument's default value and data type in python?

I want to write something like this. 1) def func_name(arg1, arg2, arg3 = 3) #this defines default value for optional argument arg3 2) def func_name(arg1, arg2, arg3: int) #and this defines data type for required argument arg3 Is there any possible…
5
votes
1 answer

Complex type as optional argument in web api action

I need to make a complex type parameter optional in 'Web API controller action', so that my action filter for null values can ignore it by checking the argument's property IsOptional. I'm getting this error: Optional parameter 'errorCode' is not…
5
votes
2 answers

optional list argument "list = list or []" in python

Conventional way of dealing with optional list arguments is the following: def func(list_of_vals = None): if list_of_vals is None: list_of_vals = [] ... I wounder if the following (shorter) version has any pitfalls? why nobody do that?…
Ben Usman
  • 7,969
  • 6
  • 46
  • 66
5
votes
2 answers

Idiomatic way to make middle arguments optional

What is a common way to implement a JavaScript function whose middle argument(s) are optional, but the last argument is required? An idiomatic ES2015 solution is preferred. E.g., I commonly see functions that can be invoked in multiple ways, like…
brianmearns
  • 9,581
  • 10
  • 52
  • 79
5
votes
2 answers

How do I use MATLAB's inputParser with optional string inputs? The documentation says "use a validation function" but it's unclear how to do that

I have a MATLAB file that contains a single top-level function, called sandbox. That function in turn contains two nested functions, mysum and myprod, which are identical in functionality and what parameters they allow except that one uses @sum…
Michael A
  • 4,391
  • 8
  • 34
  • 61
5
votes
1 answer

How to specify multiple optional arguments in a function without respecting the order they are given

The below example the optional arguments must be given in order; hence ShowHeaders Must Precede ValueAdd and so on. If I want to specify ValueAdd, I*must* specify ShowHeaders: Function Example(Value1, Optional ShowHeaders = "Headers=N", Optional…
W A Carnegie
  • 2,195
  • 2
  • 14
  • 8
5
votes
3 answers

error about optional-arguments in common-lisp

SBCL 64bit, 1.1.7 If I want to create a package and use a little symbols from package :CL, I will create a package like this one: (defpackage :foo (:import-from :cl :defun :defmacro :in-package :null :car :cdr…
xiepan
  • 623
  • 4
  • 13
4
votes
2 answers

Optional arguments?

Is there a way to declare an argument as "optional" in the Go programming language? Example of what I mean: func doSomething(foo string, bar int) bool { //... } I want the parameter bar to be optional and default to 0 if nothing is passed…
thwd
  • 23,956
  • 8
  • 74
  • 108
4
votes
2 answers

How to implement optional arguments in CHICKEN?

I'm new to CHICKEN and Scheme. In my quest to understanding tail recursion, I wrote: (define (recsum x) (recsum-tail x 0)) (define (recsum-tail x accum) (if (= x 0) accum (recsum-tail (- x 1) (+ x accum)))) This does what I expect it…
4
votes
1 answer

Method dispatch with missing arguments

How can I avoid the classic Error: argument "" is missing, with no default error (see example below) when explicitly dispatching argument values to subsequent S4 methods in a given S4 method. Example Big picture Whe have a method foo()…
Rappster
  • 12,762
  • 7
  • 71
  • 120
1 2
3
14 15