In other words, not only are loops "built into some verbs (+/ -/)" but they
are built into all verbs.  But we don't really think of them as having
loops.  Ken Iverson told the following anecdote:  In J we say, "move the
army from Boston to New York"; in a scalar language you'd say for i in
range (0,n) move soldier i from Boston to New York.  Do you think of "move"
as having a loop built in?




On Sat, Feb 15, 2014 at 9:15 AM, Roger Hui <rogerhui.can...@gmail.com>wrote:

> ​> ...loops? From what I've seen loops are built into some verbs (+/ -/
> > etc), but what if you wanted to do say: add every number in the
> > vector, but for every number add 2.91, then divide that by 0.4?
> > In python:
> > range() generates a list of numbers from 0 to 9.
> > for x in range(0,10)
> >     y += (x + 2.91) / 0.4
>
> In J:
>    ((i. 10) + 2.91) % 0.4
> or
>    (2.91 + i. 10) % 0.4
> or
>    0.4 %~ 2.91 + i. 10
>
>
>
>
> On Sat, Feb 15, 2014 at 9:04 AM, Lee Fallat <ircsurfe...@gmail.com> wrote:
>
>> Thanks for the explanation Raul.
>>
>> I think I understand now that string manipulation in J is
>> non-trivial...I was following right up until the very last J sentence
>> ( 'hi',:&.(-&(a.i.'*'))&.(a.&i.)'there'), mostly because I still only
>> know a few verbs. I am starting to think J is either not for me, or my
>> way of thinking really needs to change for this language. There are so
>> many things that would seem straight forward in traditional languages
>> than J, but I will have to see!
>>
>> Some examples of what I'm thinking of would be difficult or different in
>> J:
>> Passing 3 or more parameters to a verb
>> Turning a vector into a list of arguments
>> ​​
>> ...loops? From what I've seen loops are built into some verbs (+/ -/
>> etc), but what if you wanted to do say: add every number in the
>> vector, but for every number add 2.91, then divide that by 0.4?
>> In python:
>> range() generates a list of numbers from 0 to 9.
>> for x in range(0,10)
>>     y += (x + 2.91) / 0.4
>> One other thing is interacting with the operating system...How do I
>> check to see if files, or even directories exist? Can you create
>> directories, or change permissions of files with J? The scope of J
>> seems to be very constrained to mathematics. It would be nice to use J
>> as a system programming language! Are there any examples of people
>> doing these things?
>>
>> Anyways, I apologize for being off-topic, but just some things I've
>> been thinking about. Like I said I still have to get through some more
>> learning material.
>>
>> Regards,
>>
>> Lee
>>
>>
>>
>> On Sat, Feb 15, 2014 at 11:37 AM, Raul Miller <rauldmil...@gmail.com>
>> wrote:
>> > Conceptually speaking, J has three "atomic data types":
>> >
>> > Numeric
>> > Literal
>> > Boxed
>> >
>> > Numeric types support arithmetic: 1+1
>> > Literal types are what might be called character types in other
>> languages.
>> > (ascii or unicode)
>> > Boxed types are what might be called reference types in other languages.
>> >
>> > J tries to treat numeric types as mathematical arithmetic entities. It's
>> > not perfect, and involves tradeoffs but it does a pretty good job at
>> being
>> > useful and educational while still offering decent performance with a
>> > relatively compact implementation. Also, J booleans are numeric and I
>> > vastly prefer this approach (which fits my understanding of the history
>> of
>> > booleans) over the convention of enshrining arbitrary implementation
>> > limitations.
>> >
>> > You cannot perform arithmetic directly on literals but you can, for
>> > example, compare an ascii 'A' with a unicode 'A' and get a literally
>> > correct answer. (However, unicode also includes an open ended set of
>> rules
>> > and extensions and if you want those you will probably need to implement
>> > them yourself. To avoid open-ended arguments about these issues its
>> perhaps
>> > better to refer to this type of data as 'literal' rather than
>> 'character'.)
>> >
>> > Boxes take an arbitrary array and "puts it in a box" - you get a single
>> > thing which can be treated something like a literal or a number.
>> >
>> > You cannot mix these three types in the same array, but if you put
>> > something in a box you can put the box in an array of boxes.
>> >
>> > Anyways...
>> >
>> > For some contexts you might use a list of characters (excuse me: I mean
>> > literals) to represent a string. For other contexts you might want to
>> put
>> > that list of characters in a box. If you arrange your strings as a two
>> > dimensional array they will all be padded (with spaces) to match the
>> length
>> > of the longest one.
>> >
>> > Actually, in some contexts you might want to use a list of numbers to
>> > represent a string. Sometimes arithmetic is handy.
>> >
>> > Put differently, J does not actually have a "string" data type. But you
>> can
>> > represent them using arrays.
>> >
>> > Examples:
>> >
>> >    'hello'
>> > hello
>> >    'hello';'there'
>> > ┌─────┬─────┐
>> > │hello│there│
>> > └─────┴─────┘
>> >    'hi',:'there'
>> > hi
>> > there
>> >    'hi',:&.(-&(a.i.'*'))&.(a.&i.)'there'
>> > hi***
>> > there
>> >
>> > In that last example, I made the padding character by '*' rather than '
>> '.
>> > I did this by combining the two strings as numbers rather than literals.
>> > The padding value for numbers is zero. But if I had stopped  there I
>> would
>> > have gotten ascii nulls for my padding. So I also combined them under
>> > subtracting by the numeric value for '*'.
>> >
>> > Under performs the reverse transform for the result (of the transform
>> that
>> > it performed from the arguments),
>> > http://www.jsoftware.com/jwiki/Essays/Under
>> >
>> > I hope this makes sense.
>> >
>> > Thanks,
>> >
>> > --
>> > Raul
>> >
>> > On Sat, Feb 15, 2014 at 10:31 AM, Lee Fallat <ircsurfe...@gmail.com>
>> wrote:
>> >
>> >> Thank you all for your kind replies! And to those saying how I should
>> >> really use awk for this job- I know, I was just curious! I am very
>> >> impressed by the variance in answers, and how different J really is
>> >> compared to other languages.
>> >>
>> >> Thanks again,
>> >>
>> >> Lee
>> >>
>> >> P.S. As for the input, just numbers was fine. I'm curious though what
>> >> J does when it encounters strings (and numbers!). I figured reading
>> >> through the books offered on the wiki will explain this. (+/ "hello"
>> >> "world" 100 = what? :)
>> >>
>> >> On Sat, Feb 15, 2014 at 10:20 AM, Jim Russell <jimsruss...@yahoo.com>
>> >> wrote:
>> >> > I love AWK; it (and perl) have saved my bacon many times. If your
>> >> problem involves processing fields within lines of an I/O stream in a
>> *nix
>> >> environment, of course you or I should use AWK. Particularly me, since
>> I'd
>> >> never be given a processing task involving more math than a "gozinta"
>> or
>> >> takeaway, much less anything involving polynomials, natural logs, verb
>> >> inverses, factorials, ranks above 3, and a whole bunch of stuff that J
>> >> would do for me if only I understood what it was.
>> >> >
>> >> > (I would also pick AWK if I had only 5 minutes to learn a new
>> language.)
>> >> >
>> >> > But had AWK never been invented (shudder), and I needed to write it,
>> >> would I use J? Well, not me, but I know some folks here that might
>> knock it
>> >> out using J in an afternoon or two.
>> >> >
>> >> >> On Feb 14, 2014, at 9:51 PM, Lee Fallat <ircsurfe...@gmail.com>
>> wrote:
>> >> >>
>> >> >> Hey there,
>> >> >>
>> >> >> As new user to J (but several years experience with C and Java), I
>> >> >> find it very, very interesting. The power of its one liners and
>> >> >> mathematical heritage really have me hooked.  I was wondering though
>> >> >> if it has similar capabilities as awk. What's the equivalent to this
>> >> >> awk script in J?:
>> >> >>
>> >> >> BEGIN { FS=";" }
>> >> >> { print $1+$2 }
>> >> >>
>> >> >> This script sets a FieldSeparator to ;, and then for every "row",
>> add
>> >> >> the first and second column and prints it. I would like to replace
>> awk
>> >> >> with J!
>> >> >>
>> >> >> Thank you,
>> >> >>
>> >> >> Lee
>> >> >>
>> >> >> P.S. Excuse me if I've misidentified J sentences. (Sentences ->
>> >> statements?)
>> >> >>
>> ----------------------------------------------------------------------
>> >> >> For information about J forums see
>> http://www.jsoftware.com/forums.htm
>> >> >
>> ----------------------------------------------------------------------
>> >> > For information about J forums see
>> http://www.jsoftware.com/forums.htm
>> >> ----------------------------------------------------------------------
>> >> For information about J forums see http://www.jsoftware.com/forums.htm
>> >>
>> > ----------------------------------------------------------------------
>> > For information about J forums see http://www.jsoftware.com/forums.htm
>> ----------------------------------------------------------------------
>> 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