Space punctuation can be critical given J's grammar.  Unfortunately, the
definition of the code line of the algorithm got cut at a crucial point; is
it

(<. <./ .+~)^:_  or  (<. <./. +~)^:_  ?

It is the former (since  <./  is finding a minimum value); this is the verb
in action using the Wikipedia example:

   C=. 0 _ _2 , 4 0 3 _ , _ _ 0 2 ,: _ _1 _ 0

   fw=. (<. <./ .+~)^:_

   C ; fw C
┌─────────┬─────────┐
│0  _ _2 0│0 _1 _2 0│
│4  0  3 _│4  0  2 4│
│_  _  0 2│5  1  0 2│
│_ _1  _ 0│3 _1  1 0│
└─────────┴─────────┘

Make sure you do not try the latter for this example: lots of fun there!  ;)


On Fri, Mar 25, 2016 at 3:22 PM, Raul Miller <rauldmil...@gmail.com> wrote:

> I have, more than once, taken a J program and re-implemented it in a
> different language. Sometimes taking a significant slowdown (like
> maybe a factor of 3) to do so.
>
> One reason has to do with deployment of fresh machine instances. For a
> variety of reasons, J has not been available on widely available
> machines.
>
> (That is slowly changing, now that we've got the GPL instance of J,
> but it's not an instant process.)
>
> (On the positive side, though, our community has yet to be inflicted
> with things like left-pad.io - though I could easily imagine the day
> when someone packages a wrapper for negative number {. on literals,
> later decides that that was a bad idea, and then lots of people spend
> their day talking about that and how awful it is.)
>
> Hmm... that said, for the subject line of this thread, I'd say this
> should have gone in the chat forum, and that the answer would be
> probably yes, but probably not because of anything posted in this
> thread.
>
> And, to salve my own "programming forum" conscience, I'm going to
> mention the Floyd-Warshall algorithm, which in J looks like: (<.   <./
> .+~)^:_
>
> (This takes a connection cost matrix and returns the minimum
> transitive cost. It doesn't give you the specific path, but just
> having the best path cost helps you prune most of the cruft from a
> search for a best path.)
>
> --
> Raul
>
>
> On Fri, Mar 25, 2016 at 2:59 PM, Dan Bron <j...@bron.us> wrote:
> > Every time I learn a new programming language, I spend about 2 days
> implementing utilities directly inspired (read: stolen) from J.
> >
> > Not so much hook / fork or other composition functions, but things like
> /. (key) and #: (antibase) and so on, which are unreasonably effective in
> the actual practice of programming.
> >
> >
> >
> >> On Mar 23, 2016, at 12:51 PM, David Lambert <b49p23t...@gmail.com>
> wrote:
> >>
> >> I had an assignment to write a python program, and I've used python
> daily for 15 years.  I wrote the program in j then translated to python.
> The python includes
> >>
> >> # some definitions from j
> >> hook_monad = lambda u, v: lambda y, u=u, v=v: u(y, v(y))
> >> fork_monad = lambda u, v, w: lambda y, u=u, v=v, w=w: v(u(y), w(y))
> >> hook_dyad = lambda u, v: lambda x, y, u=u, v=v: u(x, v(y))
> >> fork_dyad = lambda u, v, w: lambda x, y, u=u, v=v, w=w: v(u(x,y),
> w(x,y))
> >> At_monad = lambda u, v: lambda y, u=u, v=v: u(v(y))
> >>
> >> ----------------------------------------------------------------------
> >> 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