f is a hook, so you need to put parens around the definition when you use it separately:

   ((3 # #\@])`(,@])`[} (0 1 2 +/~ I.))0 1 0 0 0 0 1 0 0
0 1 1 1 0 0 2 2 2

 dissect ' ((3 # #\@])`(,@])`[} (0 1 2 +/~ I.))0 1 0 0 0 0 1 0 0'

works, though dissect doesn't (yet) look inside m}

Henry Rich

On 1/29/2015 6:30 AM, Linda Alvord wrote:
Raul, Your function doesn't seem to dissect.  Here's what happens.

require 'debug/dissect'
    dissect   ',`([ , 0 1})@.(0<[)/@:(* +/\) 0 1 0 0 0 0 0 0 1 0 0'

    f=: (3##\@])`(,@])`[} 0 1 2 +/~I.
    f A
0 1 1 1 0 0 0 0 2 2 2
    f
(3 # #\@])`(,@])`[} (0 1 2 +/~ I.)
    (3 # #\@])`(,@])`[} (0 1 2 +/~ I.)0 1 0 0 0 0 1 0 0
|length error: scriptd
|       (3##\@])`(,@])`[}(0 1 2+/~I.)0 1 0 0 0 0 1 0 0
|[-6] c:\users\linda\j64-803-user\temp\67.ijs

Linda

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Raul Miller
Sent: Tuesday, January 27, 2015 11:46 PM
To: Programming forum
Subject: Re: [Jprogramming] scan replace

I guess this is how I'd write that:

    f=: (3##\@])`(,@])`[} 0 1 2 +/~I.

Is that easy enough to read, or should I spell out how it works?

Thanks,

--
Raul

On Tue, Jan 27, 2015 at 10:42 PM, Joe Bogner <[email protected]> wrote:
I'm looking for some help to write a verb to find 1s and replace it
and the next two numbers with an incrementing sequence.


0 1 1 1 0 0 0 0 2 2 2 -: f 0 1 0 0 0 0 0 0 1 0 0

I tried variations of scan[1] and the recent thread on Forward Fill[2]
seems to apply

I don't understand either well enough to apply it.

I should be able to do something like this:

1. Reverse |. 0 1 0 0 0 0 0 0 1 0 0

0 0 1 0 0 0 0 0 0 1 0

2. Scan

0
0 0
0 0 1 -> replace last 3 with 1+ the largest number found,  1 1 1
1 1 1 0
1 1 1 0 0
1 1 1 0 0 0
1 1 1 0 0 0 0
1 1 1 0 0 0 0 0
1 1 1 0 0 0 0 0 0
1 1 1 0 0 0 0 0 0 1 -> replace last 3 with 1 + the largest number
found 2 2 2
1 1 1 0 0 0 0 2 2 2
1 1 1 0 0 0 0 2 2 2 0

Assuming this is a reasonable way to tackle it, what would the correct
scan be and would you use ^: to match the last value of the scan and
replace the prior three values with the >./ of the list?

3. Reverse |. 1 1 1 0 0 0 0 2 2 2 0

0 2 2 2 0 0 0 0 1 1 1


This isn't exactly what I'm looking for since I scanned in reverse. I
would be happy with this or even happier with the desired 0 1 1 1 0 0
0 0 2 2 2

Thanks


[1] - http://www.jsoftware.com/jwiki/OlegKobchenko/Ways%20to%20Scan
[2] -
http://jsoftware.com/pipermail/programming/2015-January/040706.html
----------------------------------------------------------------------
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