Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly is #^:_1

Tags:

j

So I came across this bit of code on the j website:

mask #!.fill^:_1 lst

where mask is a bit list.

Makes sense as far as it goes. The result is the obverse of mask&#, applied to lst, with the unknown values replaced with fill.

However, it doesn't seem to generalize:

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

yields a domain error, rather than "3 4", as you might expect.

What exactly is #^:_1, and why isn't it a proper obverse of #?

like image 435
theforemancrew Avatar asked Sep 28 '22 09:09

theforemancrew


1 Answers

I believe (#!._^:_1) spreads out the right argument by either taking the indexed value if the position has a one or filling in with the fill value if it is a zero.

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

It doesn't generalize completely because values other 1 or 0 will result in the domain error that you see. See case 6 on this dictionary page. http://www.jsoftware.com/help/dictionary/d202n.htm

You might also look at the way that complex numbers interact with the standard (non-obverse) version of #, as this seems more generalizable.

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 item and the imaginary component inserts n fill values. http://www.jsoftware.com/help/dictionary/d400.htm

like image 112
bob Avatar answered Oct 05 '22 08:10

bob