I believe that the APL workspace was assumed to
be operating with index origin 0 ([]io <- 0) so
+/[0] would be summation over the first axis which
is the default in J i.e. just +/
To select the non-zero elements in j would be
(0 ~: attk)#attk
J laminate ( ,: ) is described in the dictionary
(a reference that you should study) and again by
default acts by creating a new first coordinate
as indicated in APL by the [_0.5] axis (which
would have been [0.5] in index origin 1 - perhaps
the motivation for your question about [1.5]
Reusing the temporary variable z in the fashion
of your expression is somewhat questionable practice,
but the equivalent j expression would be:
z =: r ,: (0 ~: attk)#attk =: +/z
As for the prompt question, there is a distributed
solution using the keyboard input external ( 1!:1 )
(see the dictionary again) that can be used as follows:
require 'misc'
T =: 0". prompt 'ENTER TOTAL TIME '
ENTER TOTAL TIME 63.5
2*T
127
K =: prompt 'ENTER K VALUE '
ENTER K VALUE 42
$K
2
At 22:14 -0600 2006/08/06, PackRat wrote:
I'm trying to convert a series of specialized APL functions in a book I
have to equivalent J versions. I have a programming background, but
I'm a newbie at both languages (I have several APL books, but nowhere
near as much for J), so it's initially slow going. (But it sure gives
a lot of practice in learning J, though!)
Anyway, I've encountered two things so far that have stumped me:
(1) I can't figure out how to convert the APL lamination (the [_0.5])
in the following line to J code:
Z<-R,[_0.5](0#ATTK)/ATTK<-+/[0] Z
(I used J's underscore for APL's "high minus" to indicate negative and
the # to indicate APL's not equal)
How would it look if it were a positive [1.5] instead?
Additionally, how is "+/[0] Z" converted?
(2) How does one get input from a user in J without having to use a
GUI? For example, in typical APL sequences, you might have:
'ENTER TOTAL TIME'
T<-[]
and
'ENTER K VALUE'
K<-[']
(where [] and ['] are the APL quad and quote-quad characters)
What are the J equivalents for these two sequences?
I'd appreciate any help or guidance that you all can give me. Thanks!
Harvey
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm