What is # ^: _ 1

So, I came across this bit of code on a j-site:

mask #!.fill^:_1 lst 

where mask is a list of bits.

It makes sense as much as possible. The result is the front of the & # mask applied to lst, with unknown values ​​replaced by padding.

However, it does not seem to generalize:

 2 2 (#!._^:_1) 3 3 4 4 

gives a domain error, not a "3 4", as you might expect.

What exactly is # ^: _ 1, and why is it not a proper # face?

+5
source share
1 answer

I believe that (#!._^:_1) expands the correct argument, taking an indexed value if the position has one or is filled with a fill value if it is zero.

  (1 1 0 1 0 1) (#!._^:_1) 3 3 4 4 3 3 _ 4 _ 4 

It does not fully generalize, because values ​​other than 1 or 0 will result in the domain error you see. See Case 6 on this dictionary page. http://www.jsoftware.com/help/dictionary/d202n.htm

You can also see how complex numbers interact with the standard (non-obverse) version of #, as this seems more general.

 2j1 #!._ 3 3 4 4 3 3 _ 3 3 _ 4 4 _ 4 4 _ 2j1 1j2 3j0 1j1 #!._ 3 3 4 4 3 3 _ 3 _ _ 4 4 4 4 _ 

In this case, the real component of the complex argument mjn makes m copies of the corresponding right element, and the imaginary components insert the values ​​of n . http://www.jsoftware.com/help/dictionary/d400.htm

+4
source

All Articles