Mark Rosenthal wrote:
> I was experimenting with string manipulation, and one case
> that seems to generate domain errors with obverse is:
> ('$'&,@,&'$')^:_1 '$foo$'
Try moving that left paren:
'$'&,@(,&'$')^:_1 '$foo$'
foo
> Is there a formal list of "obverse-capable" primitives?
No, because more than just primitives can be inverted. You'll be surprised by
the richness of J's calculus of inverses.
However, you can interrogate the obverse (if any) of a verb, using verb b._1
. Continuing the example above [1]:
'$'&,@(,&'$') b. _1
}: :.(,&'$')@(}. :.('$'&,))
Of course, we could've tried the original formulation:
('$'&,@,&'$') b. _1
|domain error
| ('$'&,@,&'$')b._1
and learned it has no obverse (as the error indicates).
Other examples of interesting inverses:
+/\ b. _1
(- |.!.0) :.(+/\)
_22&(]\) b. _1
,/
_&#. b. _1
($&_@>:@(_&(<....@^.))@(1&>.)@(>./)@:|@, #: ]) :.(_&#.)
! b. _1
3 : '(-(!-y"_)%1e_3&* !"0 D:1 ])^:_ <.&170^:(-:+)^.y' :.!
^~ b. _1
3 : '(- -&b@(*^.) % >:@^.)^:_ ]1>.b=.^.y'"0 :.(^~)
What're your favorites?
-Dan
[1] Which tells us a little more about this obverse. It lets us predict this
result, for example:
'$'&,@(,&'$')^:_1 'foo' NB. Note no leading or trailing $
o
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm