function parameters (from WIKI)
"Mark Hahn" <[email protected]>
| Newsgroups | gmane.comp.lang.prothon.user |
|---|---|
| Message-ID | <[email protected]> |
Mark Hahn: Formal function parameters are stored in an attribute of the function called fparams_. Lenard Lindstrom: I gather the current fparams_ is an interim solution. What will the final format be? Mark: Try it and see. It is pretty much as final as anything else is in Prothon. Lenard: Will all functions have an fparam_, even those without parameters? Mark: Hmm, I don't remember. Try it and see. Lenard: This is a good start. I have a working inspect.getparspec() function now. But the default argument values come across as featureless: Prothon 0.1 Interactive Console, Build 660, Jun 24 2004 (Ctrl-D to exit) >> import inspect >> def foo(x, y=1, z=2, *a, **k): pass >> print(inspect.getparspec(foo)) [[$x, $y, $z], $a, $k, [<Object:8ef5a0>, <Object:8ef5c0>]] >> Object <Object:8ef5a0> should be "1". But default values in fparams_ have no attributes and I cannot get at the values they represent. Is this a result of evaluation of default values for each function call? Is there any way to make the values available for constant defaults? Mark Hahn: Some are function objects that load the constant data. They run at call time. We need the equivalent of str_ for them that actually runs them to see what they produce. Others are unique (singleton) objects that represent the * and ** symbols. These unique objects will produce a name like Star and StarStar when you call str_ on them. Lenard Lindstrom: Evaluating a default to get its value is of little use since it can change from call to call. An attribute giving, as a string, the actual expression that was compiled to the default expression function would be useful. I will also just have to add a default value option to the doc string format.