In order to solve your bank example, it is merely sufficient to do

    *`+/ 1.03 300 1.025 200 1.02 100
627.837

But do you need the "toggle" verb for a more general problem?

Mike

On 15/09/2010 14:54, Markus Schmidt-Gröttrup wrote:
> Is their a better way to create a verb that toggles as defined here?
>
>       toggle =: 4 : 0
> t =: -. t
> )
>       t =: 0  NB. initialisation
>
> Consider the calculation that might occur in a bank, where growing
> deposits yield a growing interest rate:
>
> 1.03*300+1.025*200+1.02*100
>
> To evaluate it the toggle verb allows to write:
>
>     (+`* @. toggle)/ 1.03 300 1.025 200 1.02 100
>
> I dislike the global variable (t), certainly there are better ways to do
> the calculation.
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to