optional-arguments

Fortran 2003 / 2008: Elegant default arguments?

懵懂的女人 提交于 2019-11-30 13:13:25
In fortran, we can define default arguments. However, if an optional argument is not present, it can also not be set. When using arguments as keyword arguments with default values, this leads to awkward constructs like PROGRAM PDEFAULT CALL SUB CALL SUB(3) CONTAINS SUBROUTINE SUB(VAL) INTEGER, OPTIONAL :: VAL INTEGER :: AVAL ! short for "actual val" IF(PRESENT(VAL)) THEN AVAL = VAL ELSE AVAL = -1 ! default value END IF WRITE(*,'("AVAL is ", I0)') AVAL END SUBROUTINE SUB END PROGRAM PDEFAULT Personally, I often ran into the problem of accidentially typing VAL instead of AVAL , i.e. the

Python optional parameters

六眼飞鱼酱① 提交于 2019-11-30 06:01:27
Guys, I just started python recently and get confused with the optional parameters, say I have the program like this: class B: pass class A: def __init__(self, builds = B()): self.builds = builds If I create A twice b = A() c = A() and print their builds print b.builds print c.builds I found they are using the exactly same object, <__main__.B instance at 0x68ee0> <__main__.B instance at 0x68ee0> But it is not what I want, since if b changed some internal state of builds, the one in c object will also be changed. Is it possible to recreate this optional parameters each time by using this

Python optional parameters

旧街凉风 提交于 2019-11-29 05:23:58
问题 Guys, I just started python recently and get confused with the optional parameters, say I have the program like this: class B: pass class A: def __init__(self, builds = B()): self.builds = builds If I create A twice b = A() c = A() and print their builds print b.builds print c.builds I found they are using the exactly same object, <__main__.B instance at 0x68ee0> <__main__.B instance at 0x68ee0> But it is not what I want, since if b changed some internal state of builds, the one in c object

Javascript: is the arguments array deprecated?

烂漫一生 提交于 2019-11-29 01:01:53
Most sites say "callee" as a property of Function.arguments is deprecated. But some sites go further and say the whole of Functions.argument is deprecated E.g. http://aptana.com/reference/api/Arguments.html Why only mention callee if the whole routine is dead in the water? I only just discovered "arguments" and it seems incredibly useful E.g: http://hungred.com/how-to/secret-arguments-array-javascript/ Alex K. Function.arguments is deprecated, but it's only deprecated in favor of the vanilla arguments object that's available within a function. (e.g. using x = arguments[i]; instead of x =

Is it necessary to check an optional argument before passing it to another optional argument?

拟墨画扇 提交于 2019-11-28 13:38:39
I have the following question concerning the usage of optional argument. Let's say I have the following routine aaa defined in module m_aaa MODULE m_aaa SUBROUTINE aaa(a, b) INTEGER :: a INTEGER, OPTIONAL :: b END SUBROUTINE END MODULE now I have a second routine that uses the module m_aaa . Is it possible to pass the optional argument like this ! Variant 1: SUBROUTINE bbb(c, d) USE m_aaa INTEGER :: c INTEGER, OPTIONAL :: d CALL aaa(c,d) END SUBROUTINE or is it necessary to check the presence of the optional argument d like this: ! Variant 2: SUBROUTINE bbb(c, d) USE m_aaa INTEGER :: c INTEGER

Optional arguments with default value in Ruby

一曲冷凌霜 提交于 2019-11-28 11:37:30
I would like to create a function that has optional arguments with default values def my_function(a = nil, b=nil, c=500) end and call the function with the arguments I would like to specify only my_function(b=100) How do I accomplish this in Ruby 1.9.2? You cannot do that (or something similar) in Ruby < 2.0. The best you could do is: def my_function(h = {}) h[:c] ||= 500 # Use h[:a], h[:b], h[:c] ... end my_function(b: 100) Arguments are bound to parameters like this: As long as there are unbound mandatory parameters at the beginning of the parameter list, bind arguments left-to-right As long

Javascript: is the arguments array deprecated?

落花浮王杯 提交于 2019-11-27 21:31:48
问题 Most sites say "callee" as a property of Function.arguments is deprecated. But some sites go further and say the whole of Functions.argument is deprecated E.g. http://aptana.com/reference/api/Arguments.html Why only mention callee if the whole routine is dead in the water? I only just discovered "arguments" and it seems incredibly useful E.g: http://hungred.com/how-to/secret-arguments-array-javascript/ 回答1: Function.arguments is deprecated, but it's only deprecated in favor of the vanilla

Is it necessary to check an optional argument before passing it to another optional argument?

跟風遠走 提交于 2019-11-27 07:46:10
问题 I have the following question concerning the usage of optional argument. Let's say I have the following routine aaa defined in module m_aaa MODULE m_aaa SUBROUTINE aaa(a, b) INTEGER :: a INTEGER, OPTIONAL :: b END SUBROUTINE END MODULE now I have a second routine that uses the module m_aaa . Is it possible to pass the optional argument like this ! Variant 1: SUBROUTINE bbb(c, d) USE m_aaa INTEGER :: c INTEGER, OPTIONAL :: d CALL aaa(c,d) END SUBROUTINE or is it necessary to check the presence

getopt does not parse optional arguments to parameters

纵然是瞬间 提交于 2019-11-27 07:12:16
In C, getopt_long does not parse the optional arguments to command line parameters parameters. When I run the program, the optional argument is not recognized like the example run below. $ ./respond --praise John Kudos to John $ ./respond --blame John You suck ! $ ./respond --blame You suck ! Here is the test code. #include <stdio.h> #include <getopt.h> int main(int argc, char ** argv ) { int getopt_ret, option_index; static struct option long_options[] = { {"praise", required_argument, 0, 'p'}, {"blame", optional_argument, 0, 'b'}, {0, 0, 0, 0} }; while (1) { getopt_ret = getopt_long( argc,

Optional arguments with default value in Ruby

你离开我真会死。 提交于 2019-11-27 06:19:48
问题 I would like to create a function that has optional arguments with default values def my_function(a = nil, b=nil, c=500) end and call the function with the arguments I would like to specify only my_function(b=100) How do I accomplish this in Ruby 1.9.2? 回答1: You cannot do that (or something similar) in Ruby < 2.0. The best you could do is: def my_function(h = {}) h[:c] ||= 500 # Use h[:a], h[:b], h[:c] ... end my_function(b: 100) 回答2: Arguments are bound to parameters like this: As long as