I am not sure how K's _ works (I do not use K because K is hostile to me
using it).

That said, here is an example of cutting in J based on indices.  It's not a
primitive though:

   3 5 7 ((I. #\) </. ]) i. 9
+-----+---+---+---+
|0 1 2|3 4|5 6|7 8|
+-----+---+---+---+

But here is how I would extract the numbers from an ip address:

   <;._2 '192.168.1.1.'
+---+---+-+-+
|192|168|1|1|
+---+---+-+-+

Or, if you do not want to have that trailing '.' be a part of the data:

   <;._2@,&'.' '192.168.1.1'
+---+---+-+-+
|192|168|1|1|
+---+---+-+-+

Meanwhile, I had trouble understanding some of your suggestions, so I will
just offer a few comments...

   f =: ' '&$:

This is almost the same thing as
   f =: ' '&f

In other words, you're going to get an error when the stack runs out of
space.  (But it's not a complete loss, read on...)

g =: :([: -.&a: <;._2@,~)

This is an adverb which when combined with a monadic verb will provide a
dyadic case.  The dyadic case does something relevant:

   '.' ([: -.&a: <;._2@,~) '192.168.1.1'
+---+---+-+-+
|192|168|1|1|
+---+---+-+-+

And if you extract f's definition and modify it with g, you get a cut verb
which uses space as the default delimiter:

      f f. g
' '&$: :([: -.&a: <;._2@,~)

As for "anonymous functions" in J... I think that addressing that question
is going to require understanding J's grammar.  To start with, you will
need to understand the difference between nouns, verbs, adverbs and
conjunctions.  After that, you will need to understand phrasal forms
(hooks, forks, and the specific definitions of various adverbs and
conjunctions).

In essence, though, "anonymous function" probably means "verb definition".
 But it can also mean other things which may or may not be relevant to what
you were thinking about.

Anyways, to read J, you need to know what the words mean (and how they are
spelled).  I have problems similar to yours, trying to read K, because I do
not understand K's grammar.  J's vocabulary page, and the pages it links
to, can be handy when looking up words:
http://www.jsoftware.com/help/dictionary/vocabul.htm

-- 
Raul

On Fri, Nov 18, 2011 at 4:07 AM, Alexander Epifanov <[email protected]>wrote:

> Hello,
>
> Its the third time I am trying to move from K to J without success.
> Stopped and the 8th chapter of "Learning J", because its the half of
> the book, but I cannot read and understand other programs, also cannot
> write simple program.
>
> Let me provide an example. on K I split IP-string: 1_'(0,&"."=" ",s)_
> " ",s:"192.168.1.1"
> I was trying to rewrite it on J, but I did not find _ (cut) or
> something like that, which splits list by indexes.
>
> I found another cut in J, so the solution is '.'cut'192.168.1.1', but
> I have to understand it.
> cut
> ' '&$: :([: -.&a: <;._2@,~)
>
> Do I understand correct that function makes train of verbs without
> round brackets?
> So its (f g) where f =: ' '&$: and g =: :([: -.&a: <;._2@,~)
> But it does not work:
> g '192.168.1.1'
> |syntax error
>
> Why, how to read J expression? In K I just cut expression from let and
> see all imtermediate results, in J it does not work.
> Also, I cannot find anonymous function {} in K, but if I understand
> correct in J it is prefferable to compose verbs.
>
> Thank you.
>
> --
> Regards,
>   Alexander.
> ----------------------------------------------------------------------
> 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