[Review] Named parameter questions

Hi, I was going to provide a (late) review for the named parameter lib, but I have some questions before I can do that. 1) I find the use of the name "keyword" for the type of the named parameter somehow odd. It does not seem to fit with what I associate with keywords. What's the rationale behind that choice. 2) The docs give the following example for mixing named and positional parameters: foo("bar", 3.14f); foo(value = 6.28f, "baz") Should print: bar = 3.14 baz = 6.28 I believe the parameter deduction in this case is too smart. Is there a way for the user of the library to enforce a rule like "No positional param after named params" on a case by case basis? 3) Section 5 has the following example // implementation of bar() template <class Params> void bar_impl(Params const& params) { // Extract arguments float x_ = params[x]; float theta_ = params[theta | pi]; float span = params[span || boost::bind(default_span, x_, theta_)]; //!! ^^^^ ^^^^ ... } IIUC this does not work. I assume the second span should refer to a named paramter object. I think it refers to the local span object. Did I miss something? Regards Thomas PS: Doug I know I am late, feel free to ignore me. -- Thomas Witt witt@acm.org

Thomas Witt wrote:
Hi,
I was going to provide a (late) review for the named parameter lib, but I have some questions before I can do that.
1) I find the use of the name "keyword" for the type of the named parameter somehow odd. It does not seem to fit with what I associate with keywords. What's the rationale behind that choice.
AFAIK "keyword arguments" is a common name for this. Python for instance uses this term.
2) The docs give the following example for mixing named and positional parameters:
foo("bar", 3.14f); foo(value = 6.28f, "baz")
Should print:
bar = 3.14 baz = 6.28
I believe the parameter deduction in this case is too smart.
Yes, in fact it's wrong and won't compile (name has no value in the second call). That will be fixed in the docs.
Is there a way for the user of the library to enforce a rule like "No positional param after named params" on a case by case basis?
I think we could implement something like that. I have to think about it a little.
3) Section 5 has the following example
// implementation of bar() template <class Params> void bar_impl(Params const& params) { // Extract arguments float x_ = params[x]; float theta_ = params[theta | pi]; float span = params[span || boost::bind(default_span, x_, theta_)]; //!! ^^^^ ^^^^ ... }
IIUC this does not work. I assume the second span should refer to a named paramter object. I think it refers to the local span object. Did I miss something?
Yes, you are right. The local should be named span_. -- Daniel Wallin

At 03:33 AM 11/23/2004, Daniel Wallin wrote:
Is there a way for the user of the library to enforce a rule like "No positional param after named params" on a case by case basis?
I think we could implement something like that. I have to think about it a little.
It may be confusing to users if different uses of the library follow different rules. Is there a serious need for anything other than the conservative "No positional param after named params" rule? (That's the rule I'm used to.) --Beman

Beman Dawes wrote:
At 03:33 AM 11/23/2004, Daniel Wallin wrote:
Is there a way for the user of the library to enforce a rule like "No positional param after named params" on a case by case basis?
I think we could implement something like that. I have to think about it a little.
It may be confusing to users if different uses of the library follow different rules. Is there a serious need for anything other than the conservative "No positional param after named params" rule? (That's the rule I'm used to.)
No the rule is fine, I just meant I needed to think about if we could enforce it easily at compile time and I think we can. -- Daniel Wallin

Beman Dawes <bdawes@acm.org> writes:
At 03:33 AM 11/23/2004, Daniel Wallin wrote:
Is there a way for the user of the library to enforce a rule like "No positional param after named params" on a case by case basis?
I think we could implement something like that. I have to think about it a little.
It may be confusing to users if different uses of the library follow different rules. Is there a serious need for anything other than the conservative "No positional param after named params" rule? (That's the rule I'm used to.)
I have the same reaction (and question). -- Dave Abrahams Boost Consulting http://www.boost-consulting.com

On Nov 23, 2004, at 1:21 AM, Thomas Witt wrote:
PS: Doug I know I am late, feel free to ignore me.
I'm not going to ignore any input, even if it is past the "official" deadline. Reviews are still most welcome and there are still some outstanding comments/questions to be resolved. Doug
participants (5)
-
Beman Dawes
-
Daniel Wallin
-
David Abrahams
-
Doug Gregor
-
Thomas Witt