Re: Package Proposal: Math_RPN

From: Date: Wed, 28 May 2003 00:19:09 +0000
Subject: Re: Package Proposal: Math_RPN
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-16755@lists.php.net to get a copy of this message
Hi Maciej, --- Maciej Szczytowski <admin@e-rower.pl> wrote: > Hi, > > Some changes: > - new method addOperator() to set a custom (user defined) operator > - new method _raiseError() which returns a PEAR error > - method getValue() now is called calculate(), and it takes new arguments - > angle's unit and is_rpn > - changed name: pile into _stack, rule into _operation > - changed keyExists() method > - removed a bug with '-' (minus) - scripts didn't know when '-' means > a > difference operator and when a negative operator, now it do :) > - name 'RPN' changed into 'Math_Rpn' > - corrected operators - exp, E, pi, e > - new operarors - mod, div > > What do you think about addOperator() method? Is this a good way to set the > user operator? I am not sure about that. Your method seems to need a function body to be passed as a parameter. That will not be too practical when one needs to use an existing function as a operator. Perhaps a better alternative would be to allow the user to pass a function/method name, something along the lines of: include_once 'Math/TrigOp.php'; function mysign($number) { return ($number >=0 ) ? 1 : -1; } $rpn = new Math_RPN(); $rpn->addOperator('csc','Math_TrigOp::csc',3,1,'cosecant of the angle'); $rpn->addOperator('sign','mysign',3,1,'sign of the parameter'); ... and have some logic in the method to detect the '::' and then use the appropriate call_user_func() or call_user_func_array() call (whichever you like best ;-) That way there is more reuse of existing functions/methods, and makes it simpler to modify them. Another alternative would be to use create_function() to generate a lambda-style anonymous function, but that would be more complicated and will not add any advantages over call_user_function() in this case. The class is looking good. Would be nice to have some unit tests, or at least some examples that show it at work. > > New version is here -> Í´‘ > ‚ò>P†C•UÙ‹http://www.maciek.maribex.wizja.net.pl/rpn/ > > Regards, > Maciek admin@e-rower.pl ===== --- Jesus M. Castagnetto (jcastagnetto@yahoo.com) Research: http://metallo.scripps.edu/ Personal: http://www.castagnetto.org/ __________________________________ Do you Yahoo!? The New Yahoo! Search - Faster. Easier. Bingo. http://search.yahoo.com

« previous php.pear.dev (#16755) next »