I would like to know if it is possible to determine if a function parameter with a default value was passed in Python.
For example, how does dict.pop work?
>>> {}.pop('test')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'pop(): dictionary is empty'
>>> {}.pop('test',None)
>>> {}.pop('test',3)
3
>>> ...
I suppose there could be historical reasons for this naming and that other languages have similar feature, but it also seems to me that parameters always had a name in C#. Arguments are the unnamed ones.
...
Hi,
I want in a good performance way (I hope) replace a named parameter in my string to a named parameter from code, example, my string:
"Hi {name}, do you like milk?"
How could I replace the {name} by code, Regular expressions? To expensive? Which way do you recommend?
How do they in example NHibernates HQL to replace :my_param to ...
Named function parameters can be emulated in PHP if I write functions like this
function pythonic(array $kwargs)
{
extract($kwargs);
// .. rest of the function body
}
// if params are optional or default values are required
function pythonic(array $kwargs = array('name'=>'Jon skeet'))
{
extract($kwargs);
// .. rest of t...
In one of the Delphi demo applications, I've stumbled upon some syntax that I didn't know the Delphi compiler accepted:
// ......\Demos\DelphiWin32\VCLWin32\ActiveX\OleAuto\SrvComp\Word\
// Main.pas, line 109
Docs.Add(NewTemplate := True); // note the assignment
I can't seem to reproduce this type of parameter passing in my own c...
Hi all.
I'm trying to write a parameterized query in ASP Classic, and it's starting to feel like i'm beating my head against a wall. I'm getting the following error:
Must declare the scalar variable "@something".
I would swear that is what the hello line does, but maybe i'm missing something...
<% OPTION EXPLICIT %>
<!-- #includ...
I’m currently working on a classic ASP project talking to an Oracle database. I’m trying to find a way to safely call an Oracle PL/SQL script and passing parameters with ADO. The currently solution builds the SQL script by hand with embedded variables like this:
strSQL = "SELECT field1, etc FROM my_table WHERE (field = '" & filter_val...
Could someone explain the differences to me? Aren't all arguments "keyword arguments"? They all have names, and can all be assigned by that name instead of the position. Do keyword arguments mean ones with default values? (Note: I'm talking about pure python, no C)
Thanks.
EDIT: I just realized there's two types of each:
def func(*arg...
What's the best/canonical way to define a function with optional named arguments? To make it concrete, let's create a function foo with named arguments a, b, and c, which default to 1, 2, and 3, respectively. For comparison, here's a version of foo with positional arguments:
foo[a_:1, b_:2, c_:3] := bar[a,b,c]
Here is sample input a...
Is there a way to have named arguments like in perl/python
for example
object.method(arg1 => value1, arg2 => value2, arg3 => 0);
in C# prior to C# 4.0?
...
I'm been looking for a way to have named function arguments / parameters appear in any order in ANTLR. Does anyone know if there is syntax to ignore order in an ANTLR parser expression?
Say there is a function foo in the language that can take two named parameters: x and y. Since they are named parameters, I'd like them to be able to be...
How can I simulate the following Python function using the Python C API?
def foo(bar, baz="something or other"):
print bar, baz
(i.e., so that it is possible to call it via:
>>> foo("hello")
hello something or other
>>> foo("hello", baz="world!")
hello world!
>>> foo("hello", "world!")
hello, world!
)
...
I'm just starting up with F# and see how you can use currying to pre-load the 1st parameter to a function. But how would one do it with the 2nd, 3rd, or whatever other parameter? Would named parameters to make this easier? Are there any other functional languages that have named parameters or some other way to make currying indifferen...
I am trying to pass the parameter constraint to PDO from an array i.e.
public function write($sql,$bindparams=''){
try{
$stmt = $this->db_connection->prepare($sql);
if($bindparams != '' && is_array($bindparams)){
foreach($bindparams as $k){
$b = $k[0]; //parameter to bind to
...
I was splitting RenameFolder to two pieces and i notice visual studios 2010 supports named parameters! (example below).
I know this has existed for a number of years in other languages. I remember a professor saying why he likes named parameters and that he uses them in all of his code. But i am sure its not in all of his code. I was wo...
So GET forms make the usual urls like
.../search/?q=apple
Can you make a form create urls like
.../search/q:apple/
...
so .Net 4 added named and optional params which are pretty sweet..I don't need to make as many 1 line overload methods.
Will that work over WCF?
...
One question regarding whether the following code should yield a compiler warning or not (it doesn't). It declares two methods of the same name/return type, one has an additional named/optional parameter with default value.
NOTE: technically the resolution isn't ambiguous, because the rules clearly state that the first method will get c...
I really this is a hugely subjective topic but here is my current take:
When calling methods which do not form part of the .NET BCL named parameters should always be used as the method signatures may well change, especially during the development cycle of my own applications.
Although they might appear more verbose they are also far cl...
In Scala 2.8.0 RC 2 this definition:
def buttonGroup[T](values: Array[T], textProvider: T => String = (t: T => t.toString)) = ...
gives the error message:
not found: value t
def buttonGroup[T](values: Array[T], textProvider: T => String = (_.toString)) = ...
gives
missing parameter type for expanded function ((x$1) =>...