On the issue of interacting with the outside world, it's easy enough to use "shell" to invoke whatever OS command you like, e.g.
dir 'Q:' NB. Empty result, but what does it mean? shell 'dir Q:' The system cannot find the path specified. J makes it easy to generalize this: +./'cannot find' E. shell 'dir Q:' 1 ltrs=. 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 13 : '+./x E. shell y' [: +./ [ E. [: shell ] notDrive=. (<'cannot find') ([: +./ [ E. [: shell ]) &> (<'dir '),&.>ltrs,&.>':' ltrs#~-.notDrive NB. Valid drive letters... CDJST On Sat, Feb 15, 2014 at 9:30 PM, Marshall Lochbaum <mwlochb...@gmail.com>wrote: > Some other people have said similar things on this topic, but here are > my thoughts: > > Your way of thinking does need to change in order to use J. It's not an > unnatural change, or even a hard change, in the sense that the J way of > thinking is just as natural and as easy as the Python (or other > imperative language) way of thinking. However, it is a large shift so > you will need to put some work into divorcing your thoughts about > programming from your knowledge of the imperative style. > > The first few things you want to do are not ends, but means--they are > ways of accomplishing tasks in Python but aren't necessarily important > in J. This means you have moved a step forward from your problem > statement to a method of solving that problem. In order to learn J, I > recommend that you prevent yourself from taking that step and consider > what you want to do rather than how you want to do it. For instance: > > > Passing 3 or more parameters to a verb > > Turning a vector into a list of arguments > What you really want to do is to work with multiple pieces of data at > the same time. This is performed easily enough by placing the data in an > array with three or more elements. And why would you want to work with a > list of arguments? It's invariable easier to pass a list. If you want to > assign a name to each element of an array of a fixed length, use > multiple assignment, for example > 'x y z' =: 4 ; 'Hello' ; 1 0 0 > x > 4 > y > Hello > z > 1 0 0 > . > > > ...loops? > J allows for loops (using similar semantics to Python's for ... in ...) > in explicit verbs, but usually general loops are not called for and a > specific case suffices. The transition from using for loops to solve > every problem to using a number of more specific cases with nicer > properties strongly parallels the historic shift from using the general > goto construct to structured loops like for and while. In this case, you > can add 2.91 to each number in the list, divide by 0.4, and then sum: > +/ 0.4 %~ 2.91 + i.10 > 185.25 > . > > As for interacting with the outside world, a class of verbs called > foreigns form J's interface to the outside world: > http://www.jsoftware.com/help/dictionary/xmain.htm > Many of these have aliases or nicer versions (e.g. fread is a wrapper > for 1!:1) in the standard library, but I don't know where all these > verbs are documented. > > Marshall > > On Sat, Feb 15, 2014 at 12:04:13PM -0500, Lee Fallat 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 > -- Devon McCormick, CFA ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm