mean=:+/%#
   mean 1 2 1 2
1.5
   mean *: 1 2 1 2
2.5
   
   (+/%#) *:  1 2 1 2
2.5
   
   +/%#*:  1 2 1 2
0.25
   
   msg1 =: 13 :'(+/%#)*:y' 
   msg1 1 2 1 2
2.5
   
   msg2=:(+/%#)@:*: 
   msg2 1 2 1 2
2.5
   
   msg3=:[:(+/%#)*: 
   msg3 1 2 1 2
2.5
   
   msg1
[: (+/ % #) *:
   msg2
(+/ % #)@:*:
   msg3
[: (+/ % #) *:

@: is overkill,  and msg does the work for you.  Linda
   
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Don Kelly
Sent: Saturday, November 16, 2013 8:20 PM
To: [email protected]
Subject: [Jprogramming] Novice problem

This is a novice problem  (which arose from reading  "Easy J" by Linda
Alvort I think that I have it worked out but this is something (IMHO) that
possibly should be in a primer.
I have occasion to use what is called rms or root mean square (usually
applied to a wave form).
I can define root, mean and square and can do something like:
root mean square 1 2 1 2
or
    %:(+/%#)*: 1 2 1 2                                   NB. in 
immediate execution
1.58114                                 OK

A natural tendency equivalent to saying mean=: +/%# is to try
rms=: %:(+/%#)*:
But rms 1 2 1 2 fails.
However rms=: 3: ' %:(+/%#)*:y'  or rms=: 13: ' %:(+/%#)*:y'
   is OK
and the latter is equivalent to
rms=:[:%:[:(+/%#)*:  which works

Alternatively  rms=:%:@:(+/%#)@:*:    also works

It is obvious that either the capped fork (from use of 13: or use of @: 
work and I see
the reasoning behind this- forcing a sequential " root after mean after
square".

Am I right in assuming that immediate execution of
%:(+/%#)*:   y where y is explicitly entered
is treated as 3:   or  13:   ' %:(+/%#)*::y '  (explicitly in that the 
*:y is the argument for mean(+/%#) whose value is the argument for %: 
i.e. as in APL for which 'tacit' doesn't exist) and rms=: %:(+/%#)*:  as a
tacit verb with no argument  is parsed as a fork rather than sequentially as
desired and runs into never never land?

The classic example of 'mean=:+/%# as a verb is misleading in that the
example is a single fork, but trying to extend it does need a flag as to the
need to emphasize the parsing.
(+/%#) *:  1 2 1 2 works but msg =:(+/%#)*: doesn't work but 
msg=:(+/%#)@:*:   or msg=:[:(+/%#)*: do work


Don Kelly

-- 
  

----------------------------------------------------------------------
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