Thanks. I usually pay attention to the syntax, length and other errors but I
misses this when it seem so obvious that it "should" work.
 It's good to hear from you.

Linda

-----Original Message-----
From: programming-boun...@jsoftware.com
[mailto:programming-boun...@jsoftware.com] On Behalf Of Devon McCormick
Sent: Saturday, December 24, 2011 1:14 PM
To: Programming forum
Subject: Re: [Jprogramming] Why won;t this work?

Linda, Kip -

This is a good avenue of inquiry as Linda can help with our perennial
problem of what people have trouble with when learning J.  I'm putting
together a compendium of introductions from other programming languages to
approach this from another direction - how people are typically introduced
to programming.  We'll go over this at NYCJUG soon.

For this particular issue, I would start with the error message.  "Length
error" tells you to look at the lengths of the arguments around the
relevant verb and you know which is the relevant verb by the space
introduced by the error message into the display of the statement in
error.  I'm usually able to zero in on the proximate cause of an error by
using this technique.

Regards,

Devon


On Fri, Dec 23, 2011 at 5:42 PM, Kip Murray <k...@math.uh.edu> wrote:

> Linda, how does one investigate a problem like yours?  How can you get
> what you want?  And where can understanding be found?  I invite more
> expert comment.
>
> The problem:
>
>    (-i.10)<1{.r d
> |length error
> |   (-i.10)    <1{.r d
>
>
> Investigating: Use verb lr (linear representation) to understand the
> arguments.  Verb lr is from the !: section of
>
> http://www.jsoftware.com/docs/help701/dictionary/vocabul.htm
>
>    lr=: 3 : '5!:5 <''y'''
>
>    lr (-i.10)
> -i.10
>    lr 1{. r d
> ,_5
>
> Verb lr provides a string which, when interpreted, produces the value of
> its argument.  We see that the left argument in your problem is a vector
> of length 10 and the right is a vector of length 1, hence the length
error.
>
> Why wasn't there a problem when the right argument was the scalar _5?  I
> think that has something to do with the paragraph Agreement in the
> Dictionary's section II.B. Verbs.  Crudely, a scalar right argument can
> replicated to match the vector left argument, but a vector right
> argument cannot be so replicated.  (I hope I got that right.)
>
> Getting what you want.  Try
>
> (-i.10)<"1 0 [ 1{.r d
> 0 0 0 0 0 0 1 1 1 1
>
> The rank 1 0 tells < to compare vectors in its left argument with
> scalars in its right argument.  The [ is a standard device for
> preventing the 1 on its right from being included with the 1 0 on its
left.
>
> Finding understanding.  Perhaps Henry can suggest a reference in J for C
> Programmers.  From the Introduction and Dictionary try the Introduction
> section 20. Rank.  Dictionary section II.B. Verbs is heavy going, and
> requires going back to section II.A. Nouns.
>
> On 12/23/2011 1:41 AM, Linda Alvord wrote:
> >
> >     d=:6 _5 7 3
> >     r=: 13 :'(<./y),>./y'
> >     r
> > <./ ,>./
> >     r d
> > _5 7
> >    (-i.10)
> > 0 _1 _2 _3 _4 _5 _6 _7 _8 _9
> >    1{.r d
> > _5
> >    (-i.10)<_5
> > 0 0 0 0 0 0 1 1 1 1
> >
> >     (-i.10)<1{.r d
> > |length error
> > |   (-i.10)<1{.r d
> >
> >     (-i.10)<(1{.r d)
> > |length error
> > |   (-i.10)<(1{.r d)
> >
> >     I want something like this, but this is a simple example of what
> doesn't
> > work.
> >
> > Linda
> >
> > ----------------------------------------------------------------------
> > 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
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
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