A list of puns related to "Named parameter"
Hi,
I've just upgraded the postgresql module to 7.5.0 and get an error on the nodes:
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: no parameter named 'sensitive' (file: /etc/puppetlabs/code/environments/production/modules/postgresql/manifests/server/role.pp, line: 89) on Postgresql_psql[CREATE ROLE confluence ENCRYPTED PASSWORD ****] (file: /etc/puppetlabs/code/environments/production/modules/postgresql/manifests/server/role.pp, line: 89) on node confluence-node
The definition is the simplest:
postgresql::server::db { 'confluencedb':
user => 'confluence',
password => postgresql::postgresql_password('confluence', 'password'),
}
I tried to search any solution but... :/
Bye,
GΓ‘bor Auth
I'm a C/C++ and Python programmer by trade, so my engineering mind operates primarily in terms of variable/parametric expression.
When designing parts in FreeCAD, I like to have the ability to quickly change a core parameter of the part without having to dig through the tree view for the right component.
For the time being I'm using the "Spreadsheet" workbench to do this. I have 2 columns, one with parameter names, and the other with the values associated with these parameters. The value cells also have an "Alias" name set for each. Example:
https://i.imgur.com/ZNPbaQz.png
This allows me to reference these parameters from within the model. So say I want my part to be a certain width, I can set this value in the spreadsheet and give it a name/alias, and then use this in the expression editor when implementing constraints and so on.
But is this the proper way of doing this? Is there a purpose-made workbench for organizing and editing parameters in this way, or is the spreadsheet workbench the best option?
Is there a rule or convention regarding which is preferable? Specifically, for the following use cases
void func(this.value)
void func({required this.value})
Text("Hello", textAlign: TextAlign.center)
The only link I could find is this one to avoid boolean positional parameters:
https://dart.dev/guides/language/effective-dart/design#avoid-positional-boolean-parameters
Example of what I'm talking about:
function foo1(a: number, b: number, c: number) {}
function foo2({a, b, c}: {a: number, b: number, c: number}) {}
// call sites
foo1(1, 2, 3)
foo2({a: 1, b: 2, c: 3})
I know there is even debate in JavaScript about whether or not you should use the "trick" of using an object for input params to a function. The "for" argument is that the named parameters help the caller know which arg is which, and allows them to place them in any order. The "against" argument (AFAIK) is that it makes partial application and currying uglier.
Even though I like partial application and currying, I do tend to use the "parameter pack" approach a lot when I'm writing JavaScript.
However, I'm wondering if-and-how TypeScript changes things. For one, it seems like parameter packs are even more awkward and cumbersome in TS when it comes to partial application.
Also, with static typing, you're less likely to mix up arguments at the call site - except when several parameters have a subtype relationship (including being the same type).
So, I really haven't been using that approach with my TypeScript code. But, just recently, I did hit a point where I have a function that has 6 parameters (it's a "generic" function that will be wrapped and partially applied for specific use-cases), and some of them are overlapping types. This is making me second-guess a bit.
What are your thoughts on this old JavaScript trick and when-and-whether it's useful in TypeScript code?
Hi again friends,
I have a trait where I require implementors of my trait to also implement IntoIterator
for references to Self
. I've hit some severe writers block that I'm hoping one of you geniuses can slap me free from.
My trait represents a Vector object, for which I require the implementor to:
The first three requirements are straightforward. I'm hung up on requirement four. My first attempt would be this:
pub trait Vector:
VectorArithmetic<DType=<Self as Vector>::DType> +
FromIterator<<Self as Vector>::DType> +
IntoIterator<
Item=<Self as Vector>::DType,
IterType=<Self as Vector>::IterType
>
{
type DType;
type IterType;
fn distance(&self, other: &Self) -> <Self as Vector>::DType;
fn dot(&self, other: &Self) -> <Self as Vector>::DType;
fn dimension(&self) -> usize;
}
However this is incorrect, as it requires the implementation of IntoIterator on Self
, which moves instead of borrows. So I tried to modify my implementation like so:
pub trait Vector:
VectorArithmetic<DType=<Self as Vector>::DType> +
FromIterator<<Self as Vector>::DType>
where
&Self: IntoIterator<
Item=<Self as Vector>::DType,
IterType=<Self as Vector>::IterType
>
{
type DType;
type IterType;
fn distance(&self, other: &Self) -> <Self as Vector>::DType;
fn dot(&self, other: &Self) -> <Self as Vector>::DType;
fn dimension(&self) -> usize;
}
However, rustc complains that I can't use &Self
without a named lifetime.
error[E0637]: `&` without an explicit lifetime name cannot be used here
--> src/lsh/vector.rs:20:5
|
20 | &Self: IntoIterator<Item=<Self as Vector>::DType,
| ^ explicit lifetime name needed here
Fine, rustc, fine; I'll include the named lifetime:
pub trait Vector<'a>:
VectorArithmetic<DType=<Self as Vector>::DType> +
FromIterator<<Self as Vector>::DType>
where
&'a Self: IntoIterator<
Item=<Self as Vector>::DType,
IterType=<Self as Vector>::IterType
>
{
type DT
... keep reading on reddit β‘https://preview.redd.it/8y25dncknw361.png?width=1195&format=png&auto=webp&s=d9d03b382fc460767650fe72957d97da5ca0ba41
I often see R described as a "scripting language" but it seems to have an extremely minimal toolkit for making usable self-contained scripts that have any kind of complexity out of the box. My biggest gripe here is that `commandArgs()` does not support named parameters for scripts.
It doesn't look like the community has settled on a "standard" library like Python's `argparse` for handling argument parsing and consequently there are at least a dozen different packages for addressing this issue out there, none of which I have any assurance that my users will have or be able to install at runtime (my users have whatever packages are distributed with Microsoft Machine Learning Server but no assurance of CRAN/MRAN access and I would strongly prefer not to have my scripts trying to install dependencies from github at runtime just so that they can interpret arguments).
Is there an easy solution for making usable scripts (ideally including some kind of support for documentation) that I'm overlooking?
Not sure if this is the appropriate/best place to ask this, so apologies if it isn't (please redirect me to a better subreddit in this case).
Anyway, I want to improve my programming style by adapting one of the above (tacit programming vs named parameters), since it seems both can provide similar benefits but are somewhat at either end of a spectrum with each other, so it seems impossible to use both simultaneously (at least on the same function). I thought it'd be a good idea to ask this question here since I know many people knowledgeable about programming language design frequent it, and who better to ask about programming style than people who design the languages themselves. Surely some of you must be well-versed on the pros and cons of both styles and probably have some interesting opinions on the matter.
That being said, which one do you think is more readable, less error-conducive, versatile and better in general? Please give reasons/explanations for your answers as well.
Edit: I think I've maybe confused some people, so just to be clear, I've made some examples of what I mean regarding the two styles in this comment. Hopefully that makes my position a bit clearer?
Hello all,
i wrote a litte test function to find out why a named parameter cannot be empty but i stuck at some point.
Function test-ui() {
PARAM(
[Parameter(Mandatory=$False)]
#[AllowEmptyString()]
[string]$ConfigFile,
[Parameter(Mandatory=$False)]
[switch]$Run
)
BEGIN {}
PROCESS {
If($ConfigFile){
If($ConfigFile -ne $Null){ Write-Host "FileName is $($ConfigFile)" }
If($ConfigFile -eq $False){ Write-Host "No such file specified" }
}
If($Run.IsPresent){
If($Run -eq $True){ Write-Host "Run" }
}
}
END {}
}
When I call this funtion with ...
>PowerShell.exe -NoExit -ExecutionPolicy ByPass -Command "& { . .\test.ps1; test-ui -ConfigFile ''; test-ui -Run}"
>
>PowerShell.exe -NoExit -ExecutionPolicy ByPass -Command "& { . .\test.ps1; test-ui -ConfigFile 'config_file_1'; test-ui -Run}"
... than only the one where I defined "-ConfigFile 'config_file_1'" generates a output. The one with -ConfigFile '' not recognized by the function.
Can anyone explain how I can use an empty "-ConfigFilΓΆe" which generates an output "No such file specified" like inb the if statemnent?
Cheers
If LE have someone in mind and are waiting for the tip that leads to a search warrant, what would that tip have to be, a name, a false alibi revealed, a suspicious relative, a weapon, surely one of these in there own wouldnβt be enough, so in my opinion LE are waiting for more than just one tip, they are waiting for a few tips relating to the same POI. If they have someone in mind like a few people have indicated surely they could release a bit more info to maybe help turn over more stones, for example, if there POI has a white car, a certain make and model, LE could release a statement saying something like, βdoes anybody know the whereabouts of such a vehicleβ, now Iβm only using this as an example but it could be something along those lines, or did anybody see a white male near the CPS building on such and such a time or day, maybe this could help in retrieving a warrant, Iβm sure that as more parameters are met a search warrant becomes easier to obtain. Let me know your thoughts, what do u think? Hope this makes sense.
I have a bunch of scripts that get called by a CI system to compile and package an executable, everything works apart from one annoying edge case.
When I first wrote the scripts they accepted two parameters, which where automatically passed in by the CI system. But as time went on, requirements changed, and now three parameters are passed in.
The problem comes with running older builds again. They still expect two parameters but CI system now passes in three, which inevitably causes an error.
C:\blip\dev\tools\TeamCityBuildScripts\TC_step_01_Teamcity_setup.ps1 : A
parameter cannot be found that matches parameter name 'build_ID'.
+ CategoryInfo : InvalidArgument: (:) [TC_step_01_Teamcity_setup.ps1],
ParentContainsErrorRecordException
+ FullyQualifiedErrorId :
NamedParameterNotFound,TC_step_01_Teamcity_setup.ps1
Is there anything I can add to tell PowerShell to ignore the extra parameter, or implement something like the **args
functionality from python?
Someone please tell me wth they're thinking. If this ships I'll have to put up another "don't use this feature" sign at work.
I've been strangely optimistic about PHP lately, so I suppose something had to come up.
EDIT: Someone on internals agrees: https://externals.io/message/111161#111178
Andreas, you're my hero, despite your futile efforts.
EDIT2: I'm intrigued by the down-votes. I think the feature is obviously broken, so if you disagree what's your reasoning?
Yes, the title is a bit clickbaity, but lately I've been seeing talks and RFCs on the matter, so I started wondering about this.
I feel like named parameters were a thing when everyone and their neighbor was moving to Rails, so Ruby having this feature kind of made everyone ask for it. Now... I really don't think it's such a big deal? Perhaps because I feel like having too many arguments is kind of a smell, and IDEs basically remove the guessing anyway, but in the last few years I've never actually thought "having named parameters would make a difference here".
Perhaps I'm part of a minority, but I've been wondering whether people want them because it's cool to have them or because they actually need the feature.
Hi,
does anyone know why I cannot use a named parameter for the options with json_decode
?
It just says that the parameter $options is unknown. see https://3v4l.org/ig5PR
echo json_decode('[]', options: JSON_THROW_ON_ERROR);
Uncaught Error: Unknown named parameter $options
https://www.php.net/manual/en/function.json-decode.php
I can set the json payload with json: '[]'
without problems, but not the option flags.
Hi! :) I'm trying to figure out this JavaScript code and I'm getting close, it says I need a getter and I'm not sure how to define that.
The question this problem asks is: "Define a setter function named wonAward that takes a parameter for the name of an award and stores the award name in the awards array. "
Any amount of help would be appreciated!
let movie = { // Code will be tested with a different movie name: "Interstellar", director: "Christopher Nolan", composer: "Hans Zimmer", cast: { "Matthew McConaughey": "Cooper", "Anne Hathaway": "Brand", "Jessica Chastain": "Murph", "Matt Damon": "Mann", "Mackenzie Foy": "Young Murph" }, budget: 165000000, boxOffice: 675100000, awards: [],
//my code:
set wonAward(name) {
this.awards = name;
}
};
I was designing a class and encountered this dev case.
Given a typical package definition:
package myPackage {
sub new { my ($class, $plist)=@_; #space-separated keys, e.g. "one two three"
my $self= { class => $class , val01 => "01" , val02 => "02" }; #corrected, ty!
return bless $self,$class;
}
sub getClass { my $self=shift; return $self->{class}; }
};
Is it possible to use $plist ("one two three") to add a new method to the package for each parameter on instantiation
my $obj = myPackage->new("one two three"))
such that I can then call $obj->one() , $obj->two() , $obj->three() the same way that I can call $obj->getClass()?
edit: To be clear, the goal would be to add the equivalent of sub one { return 1; } , sub two { return 2; } , sub three { return 3; } to $obj.
System #1, 8 cores, psv51 Foreach-Object -Parallel throws error
PS C:\WINDOWS\System32\WindowsPowerShell\v1.0> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.17763.1490
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.1490
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
At line:7 char:13
+ $list | Foreach-Object -Parallel {
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
Could not find a parameter named 'Parallel'.
System #2, 2 cores, psv51, Foreach parallel runs fine
PS C:\WINDOWS\System32\WindowsPowerShell\v1.0> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.14393.3866
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.3866
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Why does the slightly different/newer build number of psv51 on the System #1 with more cores throw error for -Parallel
?
I know you can use positional parameters that will populate $1, $2
etc. But is there a way to set named parameters? For example, I think it would be user-friendly to assign -u
and -userName
to a parameter so that it can override a default value (also -p or --port, -pw or --password, and --uri).
Code snippet to illustrate what I'm trying to achieve:
# terminal command
./scripts/connectToDb.sh --userName secondAdmin -pw someOtherPassword
# scripts/connectToDb.sh
DB_USERNAME="${userName}" || "admin"
DB_PASSWORD="${password}" || "defaultPasswordHere"
PORT="${port}" || 5432
DB_URL="${uri}" || "http://awsUrl.com/rds/db"
# continues...
I'm using MS Access with a 9.6.13 PostgreSQL database, and I'm constructing and executing ADO pass-through queries.
I would prefer to have named parameters in many of these queries, but I get errors when I try. I don't get errors if I just use question marks. I'm guessing this is a PostgreSQL issue rather than an Access issue.
Here's an example of a VBA procedure where the query works successfully:
Private Sub Update_Item()
Dim cmd As ADODB.Command
On Error GoTo Error_Handler
Set cmd = New ADODB.Command
Set cmd.ActiveConnection = g_conn
cmd.CommandText = "UPDATE items SET i_name = ? WHERE i_id = " & lng_Item_Id
Dim param1 As ADODB.Parameter
Set param1 = cmd.CreateParameter(, adVarChar, adParamInput, 100, txt_Item_Name.Value)
cmd.Parameters.Append param1
cmd.Execute , , adExecuteNoRecords
Set cmd = Nothing
Exit Sub
Error_Handler:
MsgBox Err.Description
End Sub
However, if I want to name a parameter, it fails. For example, if I try '@item_name' as follows, I get 'ERROR: column "item_name" does not exist; Error while preparing parameters'.
Private Sub Update_Item()
Dim cmd As ADODB.Command
On Error GoTo Error_Handler
Set cmd = New ADODB.Command
Set cmd.ActiveConnection = g_conn
cmd.CommandText = "UPDATE items SET i_name = @item_name WHERE i_id = " & lng_Item_Id
Dim param1 As ADODB.Parameter
Set param1 = cmd.CreateParameter("@item_name", adVarChar, adParamInput, 100, txt_Item_Name.Value)
cmd.Parameters.Append param1
cmd.Execute , , adExecuteNoRecords
Set cmd = Nothing
Exit Sub
Error_Handler:
MsgBox Err.Description
End Sub
OK, I could then simply use question marks for parameters, but if I'm, say, updating 15 columns for a record, then having named parameters would make the SQL a whole lot easier to write and maintain. Is there a way I can use named parameters?
In my Grammar language I support type aliases (similar to TypeScript, so you can have things like "score extends int").
When writing function definitions, I no longer need to name arguments. Instead, I pass the types.
A pseudoexample:
```
intType
numeratorType extends intType
denominatorType extends intType
divideFunction numeratorType denominatorType
return numeratorType / denominatorType
```
At first I expected name conflicts, but so far what I've found is that as long as I have the ability to add a catch all rest type, I haven't yet encountered a situation where I have a name conflict because I'd have 2 of the same types as parameters.
The benefit of this system is fewer redundant naming tasks and a tighter information graph.
What languages have this pattern?
Please note that this site uses cookies to personalise content and adverts, to provide social media features, and to analyse web traffic. Click here for more information.