![]() |
| | #1 |
| int x = *((int *) NULL); Join Date: Jul 2003 Location: Banks of the River Styx
Posts: 902
| RPN & Functions Now what I'm wondering is if there is any way to implement functions with a variable number of arguments. The only bright ideas I've had so far is "don't" and to keep the first thing on the stack as a "# of parameters", for those functions that need them. So, say log could take either 1 or 2 parameters, and took the form log(number, [base]), where base is the optional parameter. So far, I suppose I could write: number 1 log or base number 2 log But keeping the # of arguments like that seems like a kludge, especially if I ever want to actually use the RPN side as a human, and not just for evaluating the results of a infix conversion. Any other ideas on how to implement this? Are there any RPN calculators out there with variable-number of argument functions - if so, how do they do it? (Reverse Polish Notation (RPN), or postfix notation)
__________________ long time; /* know C? */ Unprecedented performance: Nothing ever ran this slow before. Any sufficiently advanced bug is indistinguishable from a feature. Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31. The best way to accelerate an IBM is at 9.8 m/s/s. recursion (re - cur' - zhun) n. 1. (see recursion) |
| Cactus_Hugger is offline | |
| | #2 |
| Cat without Hat Join Date: Apr 2003
Posts: 8,492
| The function could perhaps just pop off as many arguments as it needs. If the function doesn't know how many parameters it needs, you have no choice but passing the number of arguments anyway, or perhaps an end-of-arguments sentinel.
__________________ All the buzzt! CornedBee"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code." - Flon's Law |
| CornedBee is offline | |
| | #3 |
| and the hat of Jobseeking Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,661
| I'm thinking that it should be the parser which reads either log(10) or log(10,2) and always pushes the default value onto the stack if none is specified. Then when the evaluate comes along, the correct number of parameters are always present. |
| Salem is offline | |
| | #4 |
| Cat without Hat Join Date: Apr 2003
Posts: 8,492
| But I think he's referring to functions that can take any amount of parameters, like Code: function max(parameter_bundle numbers)
result = first of numbers
for each n in numbers except first do
if n greater than result then result = n
end
end with result
max(1, 2, 3, 4, 5, 6, 7, 8) -> 8
__________________ All the buzzt! CornedBee"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code." - Flon's Law |
| CornedBee is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Functions and Classes - What did I do wrong? | redmage | C++ Programming | 5 | 04-11-2005 11:50 AM |
| calling functions within functions | edd1986 | C Programming | 3 | 03-29-2005 03:35 AM |
| Question regarding RPN and error detection | Roule | C++ Programming | 4 | 10-02-2004 01:12 AM |
| Factory Functions HOWTO | GuardianDevil | Windows Programming | 1 | 05-01-2004 01:41 PM |
| Shell functions on Win XP | geek@02 | Windows Programming | 6 | 04-19-2004 05:39 AM |