Joey K Tuttle <[EMAIL PROTECTED]> wrote:
> ... 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]
My understanding is that the author of the function(s) I refer to
worked under the assumption of a default index origin of 0 (which, I
believe, is J's default, too).
Actually, I very deliberately had both a negative and positive example
to see how to handle both cases. The original code had the negative.
The reason behind this portion of my question was that I was wondering
whether the negative axis-specifier meant (as in other APL commands)
working from the last dimension backward and how this would look in J.
My guess was that the _0.5th dimension might have been a new last or
next-to-last dimension, but you didn't seem to address that question.
Is that the case, or what? And, if so, how would it look in J?
The positive case was just an arbitrary positive axis-specifier that
would NOT resolve to the first dimension, but to a new SECOND
dimension. I was curious to see how that pattern would look in J.
Yes, I've looked in the Dictionary and other helps. The problem with
the Dictionary is that it's very useful as a quick reference for
experienced J users but next to impossible for newbies. I'm of the
opinion that people new to J (and I mean NEW to the concepts and
approach of J, not necessarily just "converts" from other programming
languages) need at least 4-5 times as many examples for each primitive
and a LOT more explanatory text. Of course, that turns it from a
"dictionary" into an "encyclopedia"! ;-) A further example of what
could be included are diagrams similar to the excellent ones found in
"An Introduction to APL" by S. Pommier (Cambridge University Press,
1983). The tutorials and the Primer are quite good for introducing
things, but by their nature they stop short of the really full
descriptions and examples needed for the more advanced primitives.
It's sort of like "we've taken you through everything you need to know
for the beginner's end of the pool; the deep end is up to you to figure
out on your own." The Dictionary, for example, tells WHAT each
primitive does and HOW to use each primitive, but it doesn't say WHY
you would want to use each one (for example, in what situations this
would be the typical primitive to use). It sort of assumes that that's
a dumb question because anyone who knows J ought to know why you'd use
a particular primitive.
I'm looking at J like learning a non-English language. When you're a
beginner, you tend to want lots of patterns and examples to follow.
When you translate from one language to another, you initially tend to
do a lot of word-by-word translation. The semantic facility with
language that Oleg mentioned in his response only comes after a lengthy
acquaintance with a language, when you develop a "feel" for the
language and you become able to understand phrases and idioms and
nuances that may not make sense to a beginner. It's at the more
advanced stage that you can create literary works rather than language
exercises. (Elegant J programs are the programming equivalent of
"literary works".)
Right now, I have a need to get a working set of translated functions
as quickly as I can. I have 114 APL functions to translate, which
could take many months or even years (assuming I do nothing else) at
the rate I'm going. (I'm 60 and would like to finish long before I
die, so that I can actually USE and adapt these functions!) That's why
I need to find "quick and dirty" patterns for translating quickly so
that I can have working functions, not necessarily the "best worded"
functions. After I get a better handle on J, I figure I can go back
and do more of the code massaging to create more efficient and
idiomatic code.
> 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
The original author (who may be dead because he was already elderly 20
years ago when he published these functions) reused temporary variables
this way quite often in his functions, so at the moment I'm just taking
things as I find them.
Previous to my asking my question, I had come up with this:
z =. r , [_0.5?] ( 0 ~. attk ) / attk =. +/[0?] z
where the square-bracketed stuff was my questions.
This compares favorably with yours:
z =: r ,: (0 ~: attk)#attk =: +/z
Now I have an additional question: was your "#" a typo? I presumed the
"/" would stay the same between languages.
And one more question: since my variable assignments are all local
variables within a function, I presumed that "=." and "~." were the
proper choices. Is that a correct understanding? If not, could you
explain why "=:" and "~:" would be better choices for local variable
assignments within a function?
Thanks in advance for clarifying all of these things for me!
Harvey
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm