Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

D: function parameter name introspection

Given a function declaration in D, is it possible to introspect at compile time the string representation of any function parameter names, for use in say automatic function reflection. E.g.

void foo(int a, double b, string c) { }
register_function!(foo)()

Can register_function extract "a","b","c" at compile time in a similar way that __traits(allMembers,someClass) can for a class?

like image 569
John Avatar asked Nov 03 '10 00:11

John


People also ask

How do you name a parameter?

The parameter name is a string of alphanumeric characters starting with a letter that does not contain spaces or special characters.

What is a parameter name in Python?

Function Parameters Parameters are variables that are defined in the function definition. They are assigned the values which were passed as arguments when the function was called, elsewhere in the code.

How do you check the parameters of an object in Python?

The inspect module helps in checking the objects present in the code that we have written. We are going to use two methods i.e. signature() and getargspec() methods from the inspect module to get the list of parameters name of function or method passed as an argument in one of the methods.


1 Answers

You can use std.traits.ParameterTypeTuple!() to get the types of the parameters, but I'm not aware of any way to get their names. std.traits is continuously being improved, however, so that my get added. Odds are that is just that no one working on it has thought of that particular need, so they haven't added it yet. I would suggest creating an enhancement request for it, and there's a good chance that they'll add it.

like image 111
Jonathan M Davis Avatar answered Sep 29 '22 13:09

Jonathan M Davis