Calling a function with an arbitrary number of arguments
|
05-02-2019, 02:08 AM
Post: #1
|
|||
|
|||
Calling a function with an arbitrary number of arguments
How can I call a user-defined function with an arbitrary number of parameters from a program? Given the list of arguments and the function itself.
I tried using the python argument expansion syntax ``function(*args)`` with no luck. |
|||
05-02-2019, 06:05 AM
Post: #2
|
|||
|
|||
RE: Calling a function with an arbitrary number of arguments
Hello,
PPL does not have this type of functionality. You can however have a function with a single list argument which the function can then process as 1 variable list of arguments. Cyrille Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP. |
|||
05-02-2019, 10:56 AM
Post: #3
|
|||
|
|||
RE: Calling a function with an arbitrary number of arguments
args inside a CAS program returns the function and arguments. For example
f():=begin return args; end then f(1,23) or f(1) |
|||
05-04-2019, 03:37 PM
(This post was last modified: 05-05-2019 04:02 AM by Han.)
Post: #4
|
|||
|
|||
RE: Calling a function with an arbitrary number of arguments
Here is a short (CAS) program that takes a variable number of inputs. In this case, we expect 2 inputs but the program handles cases where more (or fewer) than 2 inputs are provided (by returning an error message). Here, the input is the variable 'args' which is (conceptually speaking) a list of values, which are then turned into a vector of values called 'argv' by encapsulating the list of values in square brackets. Non-CAS programs cannot handle variable inputs; but one way to get around this is to create a "wrapper" CAS program that handles the input and then passes it to your non-CAS program(s).
Code: #cas Graph 3D | QPI | SolveSys |
|||
06-13-2019, 08:31 PM
Post: #5
|
|||
|
|||
RE: Calling a function with an arbitrary number of arguments
This is the hack I was able to come up with, it will call the function given with as many arguments as dimensions the vector passed after it has.
Code: #cas How does this work? Why do you sum the arguments? Why do you index a sum? The sum operator is used to construct an instruction that will translate to a function call similar to ``sum(a[1], a[2], a[3])``, originated from ``a[1] + a[2] + a[3]``, the more elements you sum to that expression, the more arguments the function will receive. Some symbolic expressions besides vectors in CAS are indexable, indexing them will return parts of the expression, you can also modify the contents of the expression that way. Knowing this I created a sum with symbolic values and swapped the ``+`` operator by the function passed, then you can assign the arguments passed to the symbolic arguments used in the addition, before returning the expression we should evaluate it to perform the substitutions. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)