Yes Ric, I will take the example session you gave me and use S instead of J. 
It is below.

Don

----- Original Message ----- 
From: "Sherlock, Ric" <[email protected]>
To: "Chat forum" <[email protected]>
Sent: Thursday, April 23, 2009 8:12 AM
Subject: Re: [Jchat] Language S


>> From: Don Watson
>>
>> Thanks Ric,
>>
>>     I agree that the way to introduce a formula is to gradually work up
>> to it demonstrating as you go. I find cut and paste and the fact that
>> pressing return on an expression back a few steps brings it down
>> invaluable in doing this.
>
> You can also use Ctrl+D to get a list of your entered commands to select 
> from. Or you can use Ctrl+Shift+UpArrow to cycle through them.
>
>> In S that sequence is unbroken and consistent. In J you reach the
>> point where there is a need to change gear into tacit J and deal with a
>> completely new set of rules.
>
> Can you show an example of what you mean?
> I know there are long-time J users who use prefer not to use tacit form.
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm

========== J session ===========================================
   NB. The arithmetic mean is often used to provide an estimate of the 
middle or center of a set of values.
   NB. To calculate the mean of some values, we sum those values and divide 
the sum by the number of values
   NB. So for the values y
   y=: 4 5 6 2 3 4
   NB. The sum of the values is:
   +/y
24
   NB. the number of values is:
   #y
6
   NB. the sum divided by the number is:
   24 % 6
4
   NB. We can do this in one step:
   (+/y) % #y
4
   NB. The standard deviation is often used to provide an estimate of the 
spread of a set of values.
   NB. To calculate the standard deviation of some values,
   NB. we take the take the sum of the squared deviations of the values from 
their mean,
   NB. and then divide that number by 1 less than the number of values and 
take the square root.
   NB. The deviations from the mean are:
   y - (+/y) % #y
0 1 2 _2 _1 0
   NB. the sum of their squares is
   +/ *: 0 1 2 _2 _1 0
10
   NB. or combined:
   +/ *: y - (+/y) % #y
10
   NB. now divide by 1 less than the number of values
   (<:#y) %~ +/ *: y - (+/y) % #y
2
   NB. and finally take the square root:
   %: (<:#y) %~ +/ *: y - (+/y) % #y
1.41421
   NB. It is again helpful to define the formula as a verb for easy reuse.
   NB. Remember from all our previous work that before we store it,
    we take out all of the "y"s to the left of a right parenthesis
   NB. Where a  "y" is to the left of a verb, we need to replace it with (])
   stddev=:    %: (<:#) %~ +/ *: (]) - (+/) % #
   NB. On execution, a y is brought in to the left of every right 
parenthesis
         and at the extreme right.
    stddev y

1.41421
   stddev 3 7 4 5 8 2 3 4 5
1.94365
=====================================================

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

Reply via email to