I constrain my use of cap to the left tine of forks.  I do not apply it as a
verb, because I don't like to rely on its domain(s) being empty.

As an alternative for the use-case below, I prefer using  i.  to document &
enforce "the possible universe" of agenda selections, as in 

        f`g`h @. (0 1 3 i. select) Y

That way, anything results of select which fall outside this domain raise
index errors, which is actually more appropriate in this context (vs the
domain errors from applying [: ).  

Also, the "possible universe" is clearly documented, and the N V V fork is
not only clear & clean, but juxtaposes the possible results of select with
list of verbs which would be invoked correspondingly (1:1).

Finally, allowing for errors to be raised is often the least desirable
design for a J program (J's array-oriented nature means a failure on a
single cell results in the failure of all cells, even if most or all but one
are perfectly well formed).  The pattern above admits the standard extension
to avoid this situation:

        f`g`h`DEFAULT @. (0 1 3 i. select) Y 

Enjoy,

-Dan 


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of David Ward
Lambert
Sent: Monday, July 23, 2012 10:05 AM
To: programming
Subject: [Jprogramming] cap

Another fine application of cap:
Suppose we have an agenda selection function which returns 0 1 3 .  Cap
in this tie error checks select .

f`g`[:`h @. select Y

I regret not being able to attend the conference this year---I would
like to meet you.

Dave.

----------------------------------------------------------------------
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