parameters

Why this Ruby method passes it's argument by reference

落爺英雄遲暮 提交于 2019-12-11 02:21:20
问题 I answered on this question and stumbled on something strange. Ruby passes its arguments by value, the variables itself are references though. So why the first methods seems to pass its parameter by reference ? require 'set' require 'benchmark' def add_item1!(item, list) list << item unless list.include?(item) end def add_item2(item, list) list |= [item] end def add_item3(item, list) set = Set.new(list) set << item list = set.to_a end array1 = [3,2,1,4] add_item1!(5, array1) p array1 # [3, 2,

C# Pass a Class as a parameter

怎甘沉沦 提交于 2019-12-11 02:18:26
问题 I have an Interface, that has some methods interface IFunction { public double y(double x); public double yDerivative(double x); } and I've got static classes, that are implementing it. static class TemplateFunction:IFunction { public static double y(double x) { return 0; } public static double yDerivative(double x) { return 0; } } I want to pass this classes as a parameter to another function. AnotherClass.callSomeFunction(TemplateFunction); And some other class that catches the request

Polynomy function with changing number of parameters

不羁的心 提交于 2019-12-11 01:59:26
问题 is it possible (in Python) to define a polynomial type of function that has changing amount of parameters? Number of parameters should change according to number of data series that I have in my input file. Currently I have something like this: def y(x, a0, x2, x3, x4): y = a0 + a1*x + a2*x**2 + a3*x**3 return y I could of course set parameters of higher order to zero by extra parameter but would there be some better way. 回答1: You can loop over the arguments and evaluate the polynomial using

Template argument deduction/substitution failed, when using typename argument

北慕城南 提交于 2019-12-11 01:56:34
问题 I have the following code, which defines a template struct W that exports a type T that's based on the template argument to W : #include <iostream> using namespace std; template <unsigned N> struct Y {}; template <unsigned N> struct W { using T = Y<N>; }; I then defined this template function that looks at this type T : template <unsigned N> void foo (const typename W<N>::T& in) { //-- } The problem here is that if I try calling this function from main using one of the types exported as T ,

F# using match to validate parameters

◇◆丶佛笑我妖孽 提交于 2019-12-11 01:52:31
问题 I'm learning F#. I want to know best practices for validating input parameters. In my naivety I had thought I could do something like this: let foo = match bar with | <test for valid> -> bar | _ -> "invalid" of course that doesn't work due to mismatching types. So I'd like to see the patterns experienced F# programmers use for this sort of thing. match? If/then/else? Something else? 回答1: You are having problems because you are trying to bind a value to something that could be two possible

How to store data as a url parameter using javascript?

时光毁灭记忆、已成空白 提交于 2019-12-11 01:46:39
问题 I have a tabbed navigation menu and I have created hashed URLs for each tab. In one tab I have multiple information cards and a check box in the top right hand corner of each card. when this check box is checked the card's background color changes. My objective is that when the page is refreshed or sent as a link the cards that have been checked remain checked along with the changed background color. Any help would really be appreciated. 回答1: I think you need to use the combination of url

Is there a way to pass a method reference in Java?

て烟熏妆下的殇ゞ 提交于 2019-12-11 01:41:01
问题 This is quite difficult to phrase, but I need to be able to link a specific method to an object. More specifically, I'm making a graphics-oriented GUI, and I want to be able to assign an arbitrary method as the default "action" function for an element, such as a button. That is, I created these interfaced "graphics" objects that basically have the ability to draw themselves. I would like them to handle their own actions, so I can, for example, do something like this: GraphicObject b1 = new

Passing a parameter to a sql query using pyodbc failing

懵懂的女人 提交于 2019-12-11 01:09:47
问题 I have read dozens of similar posts and tried everything but I still get an error message when trying to pass a parameter to a simple query using pyodbc. Apologies if there is an answer to this elsewhere but I cannot find it I have a very simple table: select * from Test yields a b c This works fine: import pyodbc import pandas connection = pyodbc.connect('DSN=HyperCube SYSTEST',autocommit=True) result = pandas.read_sql("""select * from Test where value = 'a'""",connection,params=None) print

Java String Parameters

孤人 提交于 2019-12-11 01:04:16
问题 I'm coming from a .net background and want to know the accepted way of creating a method that returns a boolean and modifies a string that was passed in via parameter. I understand Strings are immutable in Java so the below snippet will always produce an empty string. I am constrained to return boolean only. Exceptions can't be thrown. If I need to wrap the String class in, say, a StringHolder, what package could I find this in. public static void DoStuff() { String msg = ""; if (GetMessage

Passing arrays as parameters in C

房东的猫 提交于 2019-12-11 01:02:24
问题 I (think I) understand that you can only retrieve the size of an array (using sizeof) if it is declared at compile time on the stack, e.g. int my_array[] = {1,2,3}; sizeof(my_array) == 3; As soon as you start using pointers you lose this length information. e.g. if you pass a pointer to int as a function parameter to get an int array into a function you can no longer use sizeof() in this way, it will just return the number of bytes used to store a pointer. Clearly, it is vital to know how