Newsgroups: comp.lang.apl
Path: watmath!watserv1!utgpu!cs.utexas.edu!wupost!darwin.sura.net!haven.umd.edu!socrates!socrates!rockwell
From: rockwell@socrates.umd.edu (Raul Deluth Miller-Rockwell)
Subject: Re: Newbie questions
In-Reply-To: ssr@tesla.caltech.edu's message of Tue, 11 Feb 1992 02:40:18 GMT
Message-ID: <ROCKWELL.92Feb10230740@socrates.umd.edu>
Sender: rockwell@socrates.umd.edu (Raul Deluth Miller-Rockwell)
Organization: Traveller
References: <1992Feb11.024018.15440@cco.caltech.edu>
Date: Tue, 11 Feb 1992 04:07:40 GMT

Steve Roy:
   Anybody got some more documentation?  I recognize that it is sort
   of a fun puzzle to pick through what there is on
   watserv1.uwaterloo.ca and figure out how to use this thing, but I
   have things I want to use this for and would rather get right to
   it.  More than a single word explaination of 'm~ evoke evoke' would
   be nice.

Well, aside from the docs on watserv1, you can order some pretty good
documentation from Iverson software.  That takes a little money and
time though.  If you've got a mac, I think there's some on-line docs
that come with the binaries for it.

I think there are a few things in the works, too.  So keep an eye on
this group.

Finally, about '~':
   avg =. +/ % #
   sum =. +/
   cnt =. #
   lst =. ? 20#10
   lst   NB. your mileage may vary
1 7 4 5 2 0 6 6 9 3 5 8 0 0 5 6 0 3 0 4
   fun =. 'avg'
   fun~ lst
3.7
   fun =. 'sum'
   fun~ lst
74
   fun =. 'cnt'
   fun~ lst
lst

In other words, ~ allows you to refer to a function using this list of
characters which represents the function's name.

   Anybody got a verbose dictionary?  I personally don't mind writing
   'Sqrt' rather than '%:' (or is it :%).  If I were Stephen Hawking I
   would probably want to minimize keystrokes, but my typing skills
   are pretty good and the limiting factor for writing and
   understanding programs is not number of keystrokes.

In j, the inflection marks always appear on the right side of the
word.  So it's %:

And, if you like, you can make yourself a list of aliases which
autoload when you start j.  You probably won't want to see them spew
across the screen every time you start j, so I'd do it like this:

----------------------------- profile.js -----------------------------
0!:3 'aliases.js'
NB. use  ^D to exit
----------------------------------------------------------------------

Then make a second file
----------------------------- aliases.js -----------------------------
curtail=. }:
gcd=.or=. +.
lcm=.and=. *.
nub=. ~.
print=. 1!:2&2
read=. 1!:1
sqrt=. %:
tail=. {:
transpose=. |:
write=. 1!:2

etc.
----------------------------------------------------------------------

It's probably worth doing, just as an exercise in seeing what you
consider important enough to name...  On the other hand, once you do
it, you'll probably find it's more trouble to look up these aliases
than it is to just use the raw commands.  [First rule of building
alias files:  only build aliases for things you do frequently enough
to remember.  Second rule of building alias files: be willing to scrap
an alias if you don't use it.]

   I'm new to J and don't really know much about its internals.  How
   efficient is it?

Oh, it could use some improvement.  But a lot depends on how you use
the language.  If you're compulsively serial in your program designs
the performance can get really, really bad...

   I see in the 4.1 source there are some interface routines that
   could presumably let you use all this stuff from C.  Is there a
   writeup on how arrays and all that are stored.  Yes, I could spend
   the time to figure it out, just wondering if someone else has done
   it and written it down somewhere.  How about an interface to
   linpack?

No interface to linpack yet, that I'm aware of.  [And this isn't going
to be something I'm going to work on, myself.]  The header file lj.h
describes the basics of the j interface, by the way.  All arrays in J
(including scalars and simple lists) are represented using the
typedef'd type 'A'.

Beyond that, jinit() initializes J (but returns 0 if something fails
like maybe not enough free memory).  jx() takes a null terminated
string and executes it.  jpr() prints to standard output.

jma(t,n,r) allocates memory (t is type, as defined in lj.h, n is
number of elements in the array, r is rank (number of dimensions in
the array)) if you want to fill in the dimensions and elements
yourself.  jfr frees stuff allocated by jma.

jset(name,array) sets name (which is a null terminated string) to
be a reference to array (in the global symbol table).  You can use
jx(name) to look up a name.

You can also set up c functions to be called from inside jx().
There's an article by Roger Hui dated 19 Apr 91 (which I've been
copying from as I compose this article) which goes into the details of
that.  Last time I checked, watserv1 had an archive of the stuff on
this newsgroup going back several years.  The last year's traffic, in
particular, is probably worth browsing if you're interested in j.
[caution: the language has evolved somewhat so a lot of the version 2
stuff won't run anymore.]

   Can a list/array hold heterogeneous objects?  That is, can I build
   a tree-type structure?  Can I build things like linked lists?  Is
   this written up somewhere?

An array can have as elements either characters, numbers, or arrays.
If the elements are arrays, they all have to be arrays, but each of
those arrays can hold something different.  So, yes, you can build
tree-type structures.  [A fact which j uses to advantage when building
functions.]

Again, you might want to browse through the archives of this
newsgroup...

[And, if you can afford the money, I really recomend getting some of
the booklets available from ISI.  If you can't afford the money, try
and get your school to spring for a batch of the things.  [Aside, does
ISI offer any kind of educational or bulk discount?  Or is the
documentation still changing too fast for that to be a good idea?]]

-- 
Raul Deluth Miller-Rockwell                  <rockwell@socrates.umd.edu>

