Note that
   marginPct=: 1 - [: %~/ [ +/ .* ]

can be simplified:
   marginPct=: 1 - [: %~/ +/ .*

(Balanced square brackets around what would be the right most verb of a
train are redundant.)

Thanks,

-- 
Raul



On Tue, Mar 18, 2014 at 12:07 PM, Devon McCormick <[email protected]>wrote:

> I thought of this too.  Also, at some point you may want to name it (here
> incorporating the suggestion to move the pairing out of the concept):
>
>    marginPct=: 1 - [: %~/ [ +/ .* ]
>    100 5 marginPct 10 3,: 7.5 2
> 0.701205
>
>
> On Tue, Mar 18, 2014 at 11:02 AM, Pascal Jasmin <[email protected]
> >wrote:
>
> > the only things I'd change:
> >
> > use ] instead of [ to be able to work in a dyadic verb
> > then make a verb, and probably assign it so as to be able to do the calc
> > another day or with other data.
> >
> >
> >
> >
> >     13 : '1- %~/ +/ x * _2]\ y'
> > 1 - [: %~/ [: +/ [ * _2 ]\ ]
> >     100 5 (13 : '1- %~/ +/ x * _2]\ y') 10 3 7.5 2
> > 0.701205
> >
> >
> >
> >
> >
> > ----- Original Message -----
> > From: Joe Bogner <[email protected]>
> > To: [email protected]
> > Cc:
> > Sent: Tuesday, March 18, 2014 9:04:59 AM
> > Subject: [Jprogramming] J as a calculator
> >
> > I'm trying to use J more in my daily calculations in addition to
> > programming.
> >
> > I was working with some simple margin % calculations in a one liner
> >
> > 1- %~/ +/ (100 5) * _2[\ (10 3 7.5 2)
> >
> > I'd like any ideas on how others would do this type of 'spreadsheet'
> > calculation. I'm pretty happy with it, but wondering if there's a more
> > clear way of expressing it in a one liner.
> >
> > Margin % is calculated as 1 - Extended Cost / Extended Price
> >
> > Or more traditionally as Price - Cost / Price
> >
> > In the example above, I have units as 100 and 5 and prices of 10,7.5
> > and costs of 3 and 2
> >
> > Price & Cost
> >
> > _2[\ (10 3 7.5 2)
> > 10 3
> > 7.5 2
> >
> > Extended Price & Cost:
> >
> > (100 5) * _2[\ (10 3 7.5 2)
> > 1000 300
> > 37.5  10
> >
> > Total Cost & Price
> >
> > +/ (100 5) * _2[\ (10 3 7.5 2)
> > 1037.5 310
> >
> > Margin %
> > 1- %~/ +/ (100 5) * _2[\ (10 3 7.5 2)
> > 0.701205
> >
> > Any ideas on making it more clear are welcome
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> >
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> >
>
>
>
> --
> Devon McCormick, CFA
> ----------------------------------------------------------------------
> 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