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

Reply via email to