373 questions
3
votes
3
answers
277
views
What is the PEP-8 guideline for a default parameter with a union type?
AFAIK, the default parameters should not have space around the = sign.
def foo(bar: str="baz")
What is the convention when there are union types?
def foo(bar: str | None=None)
def foo(bar: ...
4
votes
1
answer
136
views
Using a namespace-scope static variable as function default parameter
Is it safe to use a namespace-scope static variable (i.e., internal linkage) as the default parameter for a function declared in a header? And if so, is it guaranteed that when making a defaulted call ...
1
vote
1
answer
108
views
Why can't I add default-argument to my lambda function parameters (or is there an alternative way to do it)?
So I have a method with simple lambda functions I use to update my weights and I want to try different functions but I also want to have default parameter for the decay:
void ema_update(int i, const ...
-1
votes
1
answer
70
views
Using default values in C++ Function declaration [duplicate]
It's been quite a while (18+ years) since I've been coding in C++.
I am running into a problem with using default parameters in a function, then trying to call that function with only the non ...
0
votes
1
answer
37
views
Encountered a strange problem when writing b+trees using Python [duplicate]
Tree node structure:
class BPlusNode:
def __init__(self,isleaf = True,val=[],parent=None,children=[]):
self.values = val
self.children = children
self.parent = parent
...
1
vote
2
answers
608
views
How to write a default parameter callback function that does nothing? [Python]
I sometimes want to pass in a callback function as a parameter to my_function. However, I want the default behavior to simply do nothing.
I find myself wanting to write the following invalid lines of ...
0
votes
2
answers
204
views
Is it OK to have a mutable default argument if it's annotated as immutable?
It is generally, for good reason, considered unsafe to use mutable default arguments in python. On the other hand, it is quite annoying to always have to wrap everything in Optional and do the little ...
2
votes
1
answer
75
views
How to refer to protected members of an external class as default arguments for a constructor of a class template
Please excuse me if this is asked elsewhere (and provide a link!). I wasn't able to find an exact duplicate.
Not sure if I'm even phrasing the Q correctly.
As a minimal example:
#include <cstdint&...
-1
votes
1
answer
47
views
C# how to interpret this `this` in function definition? [duplicate]
I guess I never looked careful enough at the code I added before. Can someone help elaborate on the signature of this function? It is from .net 3.5 code, there is no default parameter support. But ...
1
vote
2
answers
181
views
How can I reference function prototype parameter default values in a #define in C++?
Suppose I have a function prototype which defaults several parameters:
bool debug_log(char* text, int len,
bool log_always = true, // Defaults to yes, log
SRgba* ...
2
votes
3
answers
142
views
How to make a default argument to parameter which takes function address?
How would I make a function that takes address of another function as a parameter so that passing it is not necessary.
My first solution was this:
void empty_func() {}
void func(void (*...
-1
votes
1
answer
233
views
Workaround Mutable Default Arguments in Python
Going through the python documentation, I came across below.
Important warning: The default value is evaluated only once. This
makes a difference when the default is a mutable object such as a
list, ...
-3
votes
2
answers
154
views
Why doesn't function overloading work when default parameters are specified?
When default parameters are not specified, function overloading works.
But, why doesn't function overloading work when default parameters are specified?
This program takes two integers and compares ...
0
votes
0
answers
21
views
Update parameter with default value in a bash script [duplicate]
I am new to bash scripting and struggle to update a parameter with a default value. I observe some of my optional parameters are not getting updated according to the user input.
Below is the ...
0
votes
1
answer
784
views
C2572 - When trying to include a function with a default parameter in another file, and then include this file in main
I am trying to build a small program in C++, to learn the preprocessor directives and how they actually work.
The program is made up of 5 files: main.cpp, file1.h, file1.cpp, file2.h and file2.cpp
In ...
0
votes
0
answers
77
views
Optionally passing values via kwargs to inner functions with default parameters
I have a outer function foo that calls two inner functions, bar1 and bar2. Each inner function (bar) has default parameters. I'd like to be able to call foo and specify whichever parameters I want, ...
0
votes
2
answers
111
views
JavaScript - Why i'm not able to pass a default parameter?
<body>
<h1>Insert here:</h1>
<button>Try</button>
<input name='myName' type="text">
<h2>No one here</h2>
<script&...
0
votes
2
answers
42
views
It is possible to use default parameter value its same function name
I would like to know if it is possible to use the function itself in its default parameter.
function somename(a,b=somename()){
return a+b;
}
somename(10);
0
votes
0
answers
30
views
I want to refactoring this code (default parameter using non-instantiated class)
my_func.h
class MyClass{
public:
OtherClass otherclass;
void func();
void func(OtherClass others);
};
my_func.cpp
#includ <my_func.h>
void MyClass::func(){
func(this->otherclass);
}
...
-2
votes
1
answer
58
views
Why do Python iterable and non-iterable keyword argument types behave differently with multiple function calls? [duplicate]
I was reading this very informative question and answer and learned about this behavior for the first time: calling
def foo(l=[]):
l.append(1)
print(l)
foo()
foo()
foo([])
foo()
prints
[1]
[...
1
vote
2
answers
278
views
Default template type based on later template type
I have a function which creates an object and inserts it into a container. In most cases, the object type is the same as that of the container elements. Then, I don't want to have to specify the ...
2
votes
1
answer
193
views
Default value for template parameter, followed by non-type parameter pack
I'm struggling to make this code work
template <typename T, typename U = int, auto... Params>
class Foo {};
int main()
{
auto foo1 = Foo<int, int, 1, 2, 3>{};
auto foo2 = Foo<...
0
votes
2
answers
138
views
TypeError with default parameters in a function - Python
Im trying to create a function that takes 6 arguments, 3 of which are "optional" given that I tried giving them default values.
This function takes in the 6 values and gives them to another ...
1
vote
2
answers
652
views
Powershell Script wont add $PSDefaultParameterValues to $profile
I'm writing a quick Powershell script to import modules and update some default parameters on various machines. I'm running into an issue where in my script when I add $PSDefaultParameterValues to ...
0
votes
0
answers
75
views
C++ force type resolution for overloaded methods
I have inherited code that looks similar to the following:
struct A {
typedef void * X;
};
struct B {
typedef void * Y;
};
struct foo {
void bar (A::X x, int a, int b) {
return;
}
...
0
votes
1
answer
596
views
ES6 Partial Object Destructuring Default Parameters In A Separated Object
Okay so there's a lot of similar questions here but none that actually address this.
What if I want to save the default parameters of a function on a separated object, in a separated file and then I ...
0
votes
0
answers
28
views
Default Function Parameters in C++ Header/Class Files [duplicate]
I have a function 'transfer(int arr[12][7], char letter = 'a')' that is in another class with a header files that takes in 2 parameters. I am trying to set the letter as a default parameter, so I ...
0
votes
0
answers
46
views
parameter gather is not used
import pandas as pd
import os
import time
from datetime import datetime
path = "/Users/tommasomasaracchio/Documents/pythonfolder"
def key_stats(gather="Total Deb/Equity (mrg)"):
...
4
votes
1
answer
15k
views
How do I set a default parameter value in powershell?
I have the following function that converts a file to Base64.
How do I make it so this function accepts a default value for the file path if one is not entered?
B64 -f $filePath
function B64{
...
1
vote
2
answers
65
views
Default params in JavaScript [duplicate]
I want to create a function with default params, but I want to use one default param and then use a custom value for the following one. For instance,
function greet(name, greeting = 'Hey', question = '...
0
votes
1
answer
132
views
Are there caveats of using mutable types as default parameters in functions in Python? [duplicate]
I have recently read about mutable default parameters in Python.
For some reason, I came up with an idea of using it like this:
data = [3, 4, 1, 8, 5, 9, 2, 6, 7]
def get_min(checked=[]):
global ...
5
votes
1
answer
17k
views
Tailwind not working when using variables (React.js)
currently have been facing this issue using tailwind and making rehusable react components where you can pass as a prop some styles as tailwind classes. The actual problem is with the "pb-{number}...
1
vote
2
answers
791
views
Best way to succinctly evaluate default parameters in Python?
Relatively new to Python, I find myself having to evaluate a lot of arguments in functions/static methods and I was thinking if there is a user-friendly way to do this, so I ended up writing a ...
0
votes
2
answers
1k
views
How to use an object as a function parameter in JS?
I created a function that should return an object with user data. I want the function to accept an object as a parameter and I'd like this object to be defined inside the function with all the values ...
0
votes
2
answers
375
views
C++ what happens when 0 is assigned to class variable in constructor
I'm trying to create a smart pointer and stumbled over the code below. Since I'm pretty new to C++, its syntax is yet something I have to get used to.
Below you can see the most important part of the ...
3
votes
2
answers
1k
views
How to set default value to param that has type keyof (from an explicit type) in Typescript
I am having trouble in Typescript passing default values to a function similar to pick from lodash.
The function accepts an object of known (non-generic) interface and a set of keys to pick and return ...
0
votes
1
answer
6k
views
How to mockk when a method's default parameters need an injected field?
My class has a method with default parameters whose values are derived from an injected parameter:
class Slack @Inject constructor(
private val brokerSettings: BrokerSettings
) {
fun alert(
...
3
votes
1
answer
160
views
How to provide a default parameter argument when the type of that parameter is a template type?
template <class V, class K>
class Pair {
public:
Pair(const K& key, const V& value = initial) { // what should "initial" be here?
// ...
}
}
For example if ...
6
votes
3
answers
3k
views
Sets the default value of a parameter based on the value of another parameter
So I want to create a function that generates consecutive numbers from 'start' to 'end' as many as 'size'. For the iteration, it will be calculated inside the function. But I have problem to set ...
1
vote
1
answer
179
views
Is there a clean way to set conditional defaults to optional parameters in python functions?
I have a function with multiple optional parameters whose default values are conditional on the non-optional parameters.
It currently looks like this:
def foo(x, y, option_1=None, option_2=None, ...
3
votes
1
answer
3k
views
Typescript - how to do a conditional return type based on optional boolean parameters with a default values
I am converting some existing JS code into TS, and we've used a pattern I can't figure out how to express correctly with typescript :
function getVehicles({
brandFields = false,
ownerFields = ...
5
votes
2
answers
3k
views
Kotlin default parameter only work at the end
I want some of my function parameter to be optional, so I used default parameter as follow :
fun defaultparameter(param1: String = "", param2: String = "", param3: Int = 0)
this ...
0
votes
1
answer
2k
views
Having trouble with None as default parameter
I am trying to understand how None as the default parameter works. I have a function that has 4 parameters, first is non-default followed by 3 parameters that are set =None.
Function: send(name, ...
1
vote
1
answer
320
views
conversion error from make_integer_sequence to integer_sequence
The following program does not compile:
#include <utility>
#include <iostream>
#define N 4
template <unsigned int I>
unsigned int g() { return I; }
template <unsigned int... I&...
8
votes
1
answer
1k
views
How to pass a function as an optional parameter with a default value in a function in dart?
This is what I want to implement:
void fun({
bool Function(int i) predicate = (i) => false,
}) {
// do something with 'predicate(something)'
}
But I am getting the error:
The default value of ...
0
votes
1
answer
40
views
Pass a function a variable while assigning it a value in the function argument? Example: myFunction( arr, newArr = [] )
I'm trying to understand what happens when a variable gets assigned a value inside a function's argument list.
For example: myFunction(arr, newArr = [])
Does this mean I'm initializing newArr within ...
0
votes
1
answer
66
views
Calling a Function with integer [[mayb_unused]] macro and default argument boolean type parameter
I am writing a Function with 2 Parameters, 1st is integer type marked [[maybe_unused]] and 2nd is Boolean Type with Default Argument false.
int preOrderTraversial([[maybe_unused]] int searchData, bool ...
0
votes
1
answer
55
views
Why doesn't passing a function with default parameters to a templatized constructor and storing it using a lambda as std::function<void()> work?
Take this simplified example:
Command.h:
class Command {
public:
template<typename Func>
Command(Func newToExecute) : toExecute([&newToExecute](){newToExecute();}) { }
void ...
-3
votes
1
answer
197
views
When the function runs multiple times, the list is nested in the default parameter, but the integer is not [duplicate]
The list, x, isn't initialized to the parameter default value each time the function is operated, but remains in the previous state and adds a new value.
That's how the function was executed 5 times, ...
2
votes
1
answer
802
views
Is Python's range() function a overloaded built-in function? [duplicate]
I have come across that only parameters at the END of a paramater list can have a default value as VALUES are assigned by position in a function as how it is defined below
def greeting(a,b=7):
...