multiple arguments, variable arguments, default values - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: multiple arguments, variable arguments, default values (/thread-16680.html) |
multiple arguments, variable arguments, default values - Wes Loewer - 04-17-2021 01:11 PM From the recent public beta announcement, (04-14-2021 06:32 AM)Tim Wessman Wrote: [*]Able to have multiple functions of same name with different number of arguments (no default arguments though) I thought someone might benefit from seeing the syntax for this. And while technically correct that PPL does not support default arguments, you can still get the equivalent of default arguments as shown below. Here's an example of multiple arguments using the same function name defined with different number of arguments. Code:
And here's a simple example of the variable argument syntax. Code:
IMHO, these are nice additions to PPL. RE: multiple arguments, variable arguments, default values - compsystems - 04-17-2021 04:32 PM Testing the code in the simulator QF(1,2,3) [enter] returns "Error: Invalid input" PHP Code: export parallelResistors_home( a, b, ... c ) 0.92307692308 > 1 / ( ½ + ¼ + 1/3) // ok parallelResistors_home( 2, 4 ) [enter] returns 1.33333333333...∞ > 1 / ( ½ +¼ ) exact(Ans) [enter] 4/3 parallelResistors_home( 1, 2, 4, 3, 5 ) [enter] returns 0.43795620438 > 1 / ( 1 + ½ + ¼ + 1/3 + 1/5 ) // ok PHP Code: #cas parallelResistors_cas(R_1, R_2, R_3) > 1 / ( (1/R_1) +(1/R_2)+1/R_3) ) > R_1*R_2*R_3 / (R_1*R_2 + R_1*R_3 + R_2*R_3) RE: multiple arguments, variable arguments, default values - Wes Loewer - 04-17-2021 05:59 PM (04-17-2021 04:32 PM)compsystems Wrote: QF(1,2,3) [enter] returns "Error: Invalid input" x^2+2x+3 has imaginary roots. Go to Home Settings and turn on Complex mode to see the results. Quote:[php]#cas I think the new syntax for multiple and variable arguments is only for PPL, not CAS programming. Also, note that there is no space between the dots and the variable name: ...c not ... c RE: multiple arguments, variable arguments, default values - cyrille de brébisson - 04-19-2021 09:50 AM Hello, Thanks, nice example and good test programs to make sure the system works. indeed, these are PPL improvements, not CAS ones... Cyrille RE: multiple arguments, variable arguments, default values - compsystems - 04-19-2021 08:39 PM > ... turn on Complex mode to see the results. change flag externally HComplex:=00; [enter] 00 // a+b*i format and complex solutions off QF(1,2,3) [enter] returns "Error: Invalid input" > "Unreral" HComplex:=01; [enter] 01 // a+b*i format and complex solutions on QF(1,2,3) [enter] {−1+1.41421356238*i, −1-1.41421356238*i } [ab/c] {−1+√2*i,−1-√2*i} HComplex:=11; [enter] 11 // a+b*i> (a,b) format and complex solutions on QF(1,2,3) [enter] { (−1, 1.41421356238),(−1, −1.41421356238 )} change the flag internally within a code PHP Code: EXPORT QF(a,b,c) |