At 08:45 +0300 2008/04/27, Volkan YAZICI wrote:
Hi Joey,
On Sat, 26 Apr 2008, Joey K Tuttle <[EMAIL PROTECTED]> writes:
The count of t ( #t ) simply counted the number of bytes in the copy
of the file.
Ok, got it.
It is easy to let small errors creep in to ad hoc explanations. I
noticed in reading the wiki that Roger had said
# word=: <;._2 t
But then, in the next example said words - similarly I posited a 3
word example but actually supplied 4 (and later thought I should have
included 5...)
To answer your questions about ;. you might like the examples given
in J for C programmers -
http://www.jsoftware.com/help/jforc/loopless_code_v_partitions.htm#_Toc191734454
In fact, I think you would find that publication very useful for
examples of j algorithmic structures. You name ;. as operator, and
that is comfortable to someone with j/apl background - but I think
you might also call + operator and that isn't the point... In j, to
avoid confusion, the nomenclature of variables, functions, and
operators are usually spoken of as nouns, verbs, and adverbs.
This may seem strange to you, but the distinctions are very
important. If you really did mean "operator" then you should also
understand that operators modify functions (which in turn perform
operations on variables). You can see that adverb modifying verb
which acts on nouns is perhaps a more clear statement.
In any case, the verb/function in question here is enclose ( < )
which I casually referred to as "box". What it does, is take any
argument (noun) and make it an atom/scalar (this is a whole topic
that you would need to look into for further understanding - again
the J for C book is a well illustrated guide).
To answer your direct request, enclosing a text string makes it a
scalar, but that scalar is displayed in a "box" hence the casual term
boxed.
'spacer'
spacer
#'spacer'
6
#<'spacer'
1
<'spacer'
+------+
|spacer|
+------+
so in the example, the left (function/verb) argument of the cut
operator/adverb ;. is < Cut can also be thought of as "apply on
partitions" - that is, to enclose/box on some partitions of the
argument noun. The right argument to the
operator/adverb in this case is _2 which says to use the last element
of the argument (in my example blank ' ') to determine partitions and
also to discard that delimiter element. In the definition of ;. it
describes the actions of the variations _2 _1 0 1 2 - but you do have
to read carefully (and perhaps try experiments) to appreciate the
implications and subtleties. In my example
# words =. <;._2 'able deed deified writer '
4
the string is "cut" into 4 scalar "words" with the assumption that
the last element of the string defines the delimiter which is
discarded.
Your assumption that |.&. might be the same as |.&.> is incorrect
because again the Dual ( &. ) is an operator/adverb which modifies
the behavior of the two functions/verbs on either side. A good
descriptive name for f&.> is "each" meaning apply f to each of the
contents of a boxed/enclosed array. The more explicit meaning is
"reverse dual disclose" that is, apply disclose ( > ) to each item,
then apply |. to that value, then perform the inverse of disclose
(which is enclose) to that item. This raises the whole topic of
inverses, they are an amazingly fertile algorithmic tool in j.
You will find that all of us who like j believe in lots of
experimentation to learn these things. The good news, when compared
to other programming languages, is that once you gain some facility
and then you envision a way something "should work" - it usually
does. Still, experimentation is your friend. Reading excellent
examples such as those in J for C is also very helpful - of course,
such exposition is the purpose of the wiki too, but always
experiment. Very few documents, in my experience, are as concise and
complete as the j dictionary. You may see it as terse and lacking
examples, but it is in a very real sense, the complete and accurate
description of j.
Clearly you have taken the effort to create a working environment - I
hope you jump into all this and enjoy it.
- joey
> The next step in the wiki example puts each of the "lines" from the
word list into a box - and the count of boxes (# word) is 173528. If
you are asking how putting the list into boxes is accomplished ( word
=. <;,_2 t ) then I think you really should try reading more in the j
documentation about "Cut" ( ;. ) which can be found in the vocabulary
section of the documentation, e.g.
http://www.jsoftware.com/help/dictionary/vocabul.htm
Rather than deal with 173528 words, perhaps a 3 word example (excerpt
from illustrated problem) would suffice.
> ]words =. <;._2 'able deed deified writer '
+----+----+-------+------+
|able|deed|deified|writer|
+----+----+-------+------+
I looked at Cuts documentation[1] but couldn't really understand what it
does. (Even checked the wiki, but no luck.) Would you mind giving some
more examples to illustrate the function of ;. operator? In the above
example you give, I just see that it splits a string into words. But I
don't think that's the actual function of ;. operator. BTW, what is a
box?
[1] http://www.jsoftware.com/help/dictionary/d331.htm
The desire is to find words which are palindromes. Again, a read in
the J documentation will show some nice tools for managing
data. Reverse ( |. ) is one of them. e.g.
|. 'spacer'
recaps
One could apply reverse to the boxed list -
|. words
+------+-------+----+----+
|writer|deified|deed|able|
+------+-------+----+----+
but in this case, what is wanted is the reversal of each of the words
(see entry for Dual ( &. ) in the vocabulary - i.e.
|. &.> words
+----+----+-------+------+
|elba|deed|deified|retirw|
+----+----+-------+------+
so if one makes a comparison of the words and their reversed form -
words = |. &.> words
0 1 1 0
Ok, I understand what |. and |.&. does. But I'd expect to |.&.words work
also. Expression raises "domain error". That suspicion is probably
because of lack of enough knowledge.
We see that the first and last are not equal, while the middle two are
palindromes. The next step simply reduces the list to only the ones of
interest -
words #~ words = |. &.> words
+----+-------+
|deed|deified|
+----+-------+
Ok, we set `words' to symmetric words in the string.
I hope you can see the benefits of trying examples like this to learn
more about J and how algorithms are expressed in it.
Thanks so much for your detailed answer. I hope I can grasp a little bit
of J to have a small idea about what some code I see does.
Regards.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm