I thought that / is something like foldr in Haskell.
For example to trace / (over) in K I can see intermediate results:
{y+x*256}\0 1 0 0
0 1 256 65536
f:{y+x*256}
f[f[f[0;1];0];0]
65536
In J:
(+ *&256)~/\0 1 0 0
0 1 256 256 - strange
Ok, have to think about it. :)
On Sun, Nov 20, 2011 at 5:34 PM, Raul Miller <[email protected]> wrote:
> To turn something into a function, you need to be able to turn it into a
> parenthesized expression. Anything that you can put in parenthesis can be
> assigned as the value of a name.
>
> If you need a hint, 13 : is a good tool (though it does not always work).
> Replace your data with y, and:
>
> 13 :'".;._1@:,~&''.'' y NB. das ist gut'
> ".;._1@:,~&'.'
>
> Note, however, that I have linear display form enabled (9!:3]5).
>
> So, anyways:
> Fn=: ".;._1@:,~&'.'
> Fn '192.0.0.1'
> 192 0 0 1
>
> As for
> +---------------------+-+-+
> |+-----------------+-+|&|.|
> ||+----------+--+-+|~|| | |
> |||+--+--+--+|@:|,|| || | |
> ||||".|;.|_1|| | || || | |
> |||+--+--+--+| | || || | |
> ||+----------+--+-+| || | |
> |+-----------------+-+| | |
> +---------------------+-+-+
>
> This is telling you that the expression is equivalent to
> (((".;._1)@:,)~)&'.'
>
> In other words:
> the first thing that happens is that the verb ".;._1@:,~ gets a right
> argument of '.'
> the second thing that happens is that '.' becomes the left argument
> of ".;._1@:,
> the third thing that happens is that the string with the leading '.'
> becomes the right argument of ".;._1
>
> As for how / works -- it just places the verb between the items of the
> array. So perhaps this will help illustrate that:
>
> (+ *&256)~/0 1 0 0
> 256
> 0(+ *&256)~ 1(+ *&256)~ 0(+ *&256)~ 0
> 256
> (+ *&256)~ 0(+ *&256)~ 0
> 0
> 1(+ *&256)~ 0(+ *&256)~ 0
> 256
> 0 (+ *&256)~ 256
> 256
> 256 (+ *&256) 0
> 256
> (*&256) 0
> 0
> 256 + 0
> 256
>
>
> In essence, the final stage of the calculation is: 256 + 0 * 256...
>
> Note, however that there are other ways to evaluate polynomials, including
> p. and also:
> 256 #.|.1 0 0 0
> 1
> 256 #.|.0 1 0 0
> 256
> 256 #.|.0 0 1 0
> 65536
>
> Anyways, I am not completely sure what you were asking, but maybe some of
> this will help.
>
> --
> Raul
>
>
> On Sun, Nov 20, 2011 at 10:26 AM, Alexander Epifanov <[email protected]>wrote:
>
>> Thank you for so many letters. But please do not too much time on me
>> :) because I have manual and I can read it.
>>
>> Now the next thing is unclear for me:
>> s =: '192.168.1.1'
>> ".;._1@:,~&'.' s .NB das ist gut
>> 192 168 1 1
>> but its not so clear how to convert it to function. I found &: but it
>> does not work:
>> (".;._2&:,&'.') s
>> |domain error
>> | (".;._2&:,&'.')s
>> its equals @: which works, and its strange, because I see that LJ
>> describes @: and &: is the same for monads.
>> f =: ".;._1@:,~&'.'
>> 5!:2 <'f'
>> +---------------------+-+-+
>> |+-----------------+-+|&|.|
>> ||+----------+--+-+|~|| | |
>> |||+--+--+--+|@:|,|| || | |
>> ||||".|;.|_1|| | || || | |
>> |||+--+--+--+| | || || | |
>> ||+----------+--+-+| || | |
>> |+-----------------+-+| | |
>> +---------------------+-+-+
>> But I do not understand how it splits the function, why does it throw
>> &',' to the top? I expected something like this
>> f =: ".;._1@:(,~&'.')
>> 5!:2<'f'
>> 5!:2<'f'
>> +----------+--+-----------+
>> |+--+--+--+|@:|+-----+-+-+|
>> ||".|;.|_1|| ||+-+-+|&|.||
>> |+--+--+--+| |||,|~|| | ||
>> | | ||+-+-+| | ||
>> | | |+-----+-+-+|
>> +----------+--+-----------+
>> f s
>> 192 168 1 1
>>
>> Ok, the next one: I suppose that / does not work like in K
>> (+ *&256)~/f '0.0.1.0'
>> 256 - cool
>> (+ *&256)~/f '0.1.0.0'
>> 256
>> again? I should be 65536 K: {y+x*256}/0 1 0 0 -> 65536
>>
>> One point: it seems that I like J style with Conjunctions more than K
>> style with x,y :) but should get used to read it.
>>
>> Ok, let it be wrong, I will correct it later.
>> g =: (+ *&256)~/ @: f
>> g s
>> 92417 - good
>> But I want to make it without g, so I am applying @: several times.
>> For the following function it works:
>> (*&2 @: *: @: +&1) 1
>> 8
>>
>> f =: (+ *&256)~/ @: ".;._2 @: ,&'.'
>> f s
>> 192 168 1 1 - does not work, only for
>> f =: (+ *&256)~/ @: (".;._2 @: ,&'.')
>> f s
>> 92417
>>
>> I suppose that it is the same question I asked above about split with @:
>>
>> Thank you,
>>
>> On Sat, Nov 19, 2011 at 2:18 PM, Raul Miller <[email protected]>
>> wrote:
>> > Have you noticed 9!:3 yet? (Or, if you are using anything but the
>> console
>> > version, there's also a menu option.)
>> >
>> > Good luck,
>> >
>> > --
>> > Raul
>> >
>> > On Fri, Nov 18, 2011 at 6:13 PM, Alexander Epifanov <[email protected]
>> >wrote:
>> >
>> >> Yes, I am ready J for C now.
>> >> But, of course, I understand most if the things.
>> >>
>> >> The main error: I thought that J is like K, but has more features.
>> >> The problem I found: J vocabulary has much more verbs. Most of the
>> >> verbs in K is one symbol, in J there are a lot of one-two-three symbol
>> >> verbs and many special construction. K is much simpler at the point .
>> >> Sometimes it is hard for me to understand what is it: 1 2 +/@:* 3 4 or
>> >> 1 2 (+/ @"*) 3 4 or 1 2 (+/@ "*) 3 4. But 5!:2 should help.
>> >>
>> >> For example I would write the following example in K:
>> >> *>|/
>> >> and for me it looks easier at the moment. Will try to overwrite it J.
>> >>
>> >> Regards,
>> >>
>> >> On Fri, Nov 18, 2011 at 11:40 PM, Kip Murray <[email protected]> wrote:
>> >> > By all means, post questions here.
>> >> >
>> >> > And I think you will like J for C programmers (click on JfC at top of
>> >> > vocabulary page), here is a sample from Chapter 2 Culture Shock:
>> >> >
>> >> > Here's an example. Figure out what the following code does:
>> >> >
>> >> > int i, j, maxcol = 0;
>> >> > float maxval = x[0][0];
>> >> > for(i = 0;i<=xsize0;++i) {
>> >> > for(j = 0;j<=xsize1;++j) {
>> >> > if(x[i][j] > maxval) {
>> >> > maxval = x[i][j];
>> >> > maxcol = j;
>> >> > }
>> >> > }
>> >> > }
>> >> >
>> >> > Not too hard. When the code finishes, maxval is the largest element
>> in
>> >> > the array x, and maxcol is the column number it was in. As it
>> happens,
>> >> > all I wanted was the column number, but there was no way for you to
>> know
>> >> > that.
>> >> >
>> >> > The same code in J:
>> >> >
>> >> > maxcol =. (i. >./) >./ x
>> >> >
>> >> > With some practice, you will learn to read this code just as easily as
>> >> > you read the C. You will recognize the / as an indicator of a loop
>> that
>> >> > accumulates a result, and the i. as an indicator of a search. The =.
>> >> > and =: tokens indicate assignment.
>> >> >
>> >> > What happened to the if statement?
>> >> >
>> >> > It's built into the >. primitive. Just as most loops are hidden
>> inside
>> >> > primitives, so are most conditionals. The functions you write can
>> also
>> >> > contain built-in conditionals.
>> >> >
>> >> > What's the statement delimiter?
>> >> >
>> >> > There isn't one. Statements are exactly one line long.
>> >> >
>> >> > I've looked at some J code. Every other character is a period or a
>> >> > colon. I've got spots before my eyes. How can anybody read this
>> stuff?
>> >> >
>> >> > . . .
>> >> >
>> >> >
>> >> > On 11/18/2011 3:45 PM, Raul Miller wrote:
>> >> >> If you cannot find the right reference material, then just post
>> >> questions
>> >> >> here.
>> >> >>
>> >> >> We have a "J for C Programmers" book, but we do not have a "J for K
>> >> >> Programmers". And in some ways, J is more complicated to use than K.
>> >> (K
>> >> >> tends to be simpler for 1 dimensional data and for tree structures.)
>> >> >>
>> >> > ----------------------------------------------------------------------
>> >> > For information about J forums see
>> http://www.jsoftware.com/forums.htm
>> >> >
>> >>
>> >>
>> >>
>> >> --
>> >> 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
>> >
>>
>>
>>
>> --
>> 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
>
--
Regards,
Alexander.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm