[Tutor] How to pass varying number of arguments to functions called by a dictionary?
Dave Angel
davea at davea.name
Wed Feb 11 17:58:35 CET 2015
On 02/11/2015 10:29 AM, boB Stepp wrote:
> On Wed, Feb 11, 2015 at 8:45 AM, Dave Angel <davea at davea.name> wrote:
>> On 02/11/2015 08:27 AM, boB Stepp wrote:
> [...]
>>
>> Sure, it's viable, but the best approach depends on your goal (use case),
>> and your restrictions. Are these functions really totally unrelated to each
>> other? You not only don't have the same number of arguments, but the values
>> don't even have anything in common?
>
> The file/module containing functions extract information from another
> software application (with its own scripting language) and ask that
> software to perform certain calculations in its scripting language.
> The dictionary keys are conventional symbols for types of calculations
> that someone might request. I have a current set of requested
> calculations, but this will likely be augmented with new ones in the
> future. Depending on the request, there might be no arguments passed,
> meaning there is a simple request for information from the software
> application that requires only a look-up, or the actual software
> application may have to do calculations requiring one or more passed
> values. Which and how many values depends on the type of calculation
> requested.
>
>> There's an implied constraint that you're not permitted to change the
>> functions. Are you really constrained to only change the caller?
>
> I think this is the case, but I am open to other ideas.
>
>> Assuming that you seriously want to be able to do this, the only use case I
>> can imagine are:
>> 1) you're writing an interpreter
>
> I was not thinking explicitly in this way, but in effect I am
> translating requests in Python code into a proprietary scripting
> language, and vice versa.
>
> [...]
>
>> In each case, there are probably better ways...
>
> I am open to suggestions!
>
So where does the data for these parameters come from? In other words,
who is your user? Why isn't that user just calling the functions
directly? You mention you're getting the function code-letters from a
data file. Are you getting the data for the parameters from there as well?
If all the data, and the corresponding function codes, are coming from
the data file, then you must be deserializing that file in some way.
And unless the data is always strings, there's more work to do there
than in the wrapping of the calls themselves.
There are libraries for serializing and deserializing arbitrary data.
Some use xml, some use json, axon, csv, YAML, and probably tons of
others. Likewise there are protocols such as SOAP, for remote procedure
calls.
Is the file entirely linear, or are you going to be doing branching,
subroutining, etc? If there's any more complexity, you need to see the
whole picture before you just do the call.
Do any of these functions have return values? How are you handling that?
--
DaveA
More information about the Tutor
mailing list