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