Newsgroups: comp.lang.apl
Path: watmath!watserv1!utgpu!news-server.csri.toronto.edu!rpi!batcomputer!caen!sdd.hp.com!wupost!darwin.sura.net!haven.umd.edu!socrates!socrates!rockwell
From: rockwell@socrates.umd.edu (Raul Deluth Miller-Rockwell)
Subject: Re: problems converting to tacit form
In-Reply-To: keil@apollo.hp.com's message of Fri, 31 Jan 1992 23:50:32 GM
Message-ID: <ROCKWELL.92Jan31235447@socrates.umd.edu>
Sender: rockwell@socrates.umd.edu (Raul Deluth Miller-Rockwell)
Organization: Traveller
References: <1992Jan31.235032.26030@apollo.hp.com>
Distribution: comp
Date: Sat, 1 Feb 1992 04:54:47 GMT

Mark Keil:
    I'm having trouble with the convert to tacit conjunction.  It
    seems very fragile, and sometimes very slow.  It would sure be
    helpful if J would give a clue where in an expression an error
    lies.

If the conversion routine doesn't work, try converting a single
sub-function of your expression.  Also, look at the resulting form.  

    I would really like to see the tacit form of some of these
    expressions.  Particularly the w expression...

I'll see if I can puzzle it out.

   $ j_3.4_sun4
   J 3.4   Copyright (c) 1990 1991, Iverson Software Inc.  All Rights Reserved.

      m=. '(+/ % #) y.'        <<<< from programming in J
      m ttt
   syntax error

Um.. wait a minute.  What's 'ttt'?  If it's undefined, here's how it
reduces (I'll use '::' to indicate end-of-input-text):

  input stack           evaluation stack           Grammar rule
::  m ttt                                          shift
::  m                      'ttt'~                  shift
::                      '(+/ % #) y.' 'ttt'~       shift
                        :: '(+/ % #) y.' 'ttt'~    syntax error

Ok, that looks gory.  Here's the verbal description:
ttt is undefined, so it's treated as a forward reference to the
function named 'ttt'.  m is a string, so it is treated as that string.
The result is a noun to the left of a verb -- a syntax error.

I suppose it would be more informative if you could get a grammatical
description of the error (here it might be "noun verb").  And maybe
even more helpful if the representations of the objects on the
evaluation stack were presented.  But that could get rather akward if
one of the objects was a 40000 element array.

I've been thinking about writing a "debugger/emulator/tracer" but I'm
not quite sure how I should do the interface code.  [And, that's
really most of the work in writing something like that.]

Anyways, skipping forward...

      ttt =. : 11
      f =. 'x.+y.'
      f ttt
   +-+-+-+
   |[|+|]|                    <<<< ok, this one works...
   +-+-+-+

Yeah, well, it does help that 'ttt' has a definition ;-)


      qlmt=.0 5 1 0.2 1 1.7 2.3 2.7 2.9
      w =. '' : '(x{x.)+(((x+-.(x+1)=$x.){x.)-((x=.<.x){x.))*1|x=.3+(y.-0{x.)%2{x.'
      qlmt w 2.3
   1.88
      w : 11
   domain error               <<<< say what? , and where?

Right, w is a function.  The (: 11) adverb wants a string argument.
When I try 
   '(x{x.)+(((x+-.(x+1)=$x.){x.)-((x=.<.x){x.))*1|x=.3+(y.-0{x.)%2{x.' : 11
I get a rather _large_ result (30 rows high, 354 columns wide).

I'm not sure I wan't to burden net news with this displayform, but if
you can't get it working, let me know and I'll mail it to you.

But, let me try to come up with a similar expression:
   first  =. 0&{
   second =. 1&{
   third  =. 2&{

   x1 =. 3&+ @((] - first @[) % third @[
   x2 =. <. @x1
   a =. x2 { [
   b =. x2 + -. @(>: @x2   =  $ @[)
   c =. x2 * 1&| @x1
   w =. a + b - c

Now, does that even look like the right algorithm?  [I'm not sure what
kind of data I'm supposed to be feeding this thing, so I can't test it
very easily.]

      d=. '3+(y.-0{x.)%2{x.'
      d
   3+(y.-0{x.)%2{x.
      d ttt
   index error                  <<<< what does this mean in this context?

I believe x. is treated as a scalar zero which (: 11) does it's work.
So, 2 { 0 is an index error  (actually, under J 3.4, 0 { 0 is an index
error).  Anyways, J 4.1 seems to handle the thing properly:
   '3+(y.-0{x.)%2{x.' : 11
+-------+-+-------------------------------------+
|+-+-+-+|@|+-------------------+-+-------------+|
||3|&|+|| ||+-+-+-------------+|%|+-------+-+-+||
|+-+-+-+| |||]|-|+-------+-+-+|| ||+-+-+-+|@|[|||
|       | ||| | ||+-+-+-+|@|[||| |||2|&|{|| | |||
|       | ||| | |||0|&|{|| | ||| ||+-+-+-+| | |||
|       | ||| | ||+-+-+-+| | ||| |+-------+-+-+||
|       | ||| | |+-------+-+-+|| |             ||
|       | ||+-+-+-------------+| |             ||
|       | |+-------------------+-+-------------+|
+-------+-+-------------------------------------+

   i=.'y.+2'                     <<<< AH, there has to be a space after =.

No, no space necessary here.  Works fine on my machine.

You've definitely found some bugs in your version of J.  I run into
them too at times (like recently when I used i. as a termination
predicate on a loop).  But I think maybe you're getting frustrated too
easily.  [Time to sit back, take a break, or go for a walk.]

Have fun,

-- 
Raul
<rockwell@socrates.umd.edu>
