Hi, Raul, >> The problem looks to me, instead, that copy is sensitive to the axes >> of the zero it receives when the argument to powerSet is empty. >> >> '' # 1 1$0 >> |length error >> | '' #1 1$0 > > No, I am using #~ >
I apologize for that mistake in my example code. I see now that if the right-hand portion of your program returned empty instead of 1 1$0 when it received an empty argument, the hook would result in ace. That result would, however, have the same flaw that you pointed out with my attempted fix: >> ec=: 0:`] @. (1<#) >> powerSet=: <@#~ ec@(2#:@i...@^#) > > #$powerSet '' > 0 > #$powerSet 'abc' > 1 > > Your special case does not produce a list of sets. > The difficulty of correcting for this is high enough that the use of Adverse (::) may well be the best. However, I've moved from being excited about such use of Adverse to a preference to avoid it. The main problem I see with this technique is that it clouds the identification of errors. If an error occurs that is not due to the empty-set edge-condition for which it was implemented, such code obscures that fact. The alternative is to code things so that the entire domain of the verb is handled without letting any of it count as an error at any point. My attempt to do that has highlighted a problem I've come up against before for which I do not have an elegant solution. The amended code for power set, below, has two portions. The main portion is the hook you wrote. The rest are addendums required to work around the problems that occur when the input is an empty noun. powerSet=: ,@( <@#~ ec@( 2#:@i...@^# )) NB. ~~~ ~~~~ ~~ I've underlined the portions that aren't "the core." The way the edge-handling code is spread through the verb strikes me as unfortunate. I'd like to be able to see your hook more plainly, perhaps like this: powerSet=: ( <@#~ 2#:@i...@^# ) AdjustForEmpty where AdjustForEmpty is an adverb that corrects these problems by implementing the difference between your original powerSet and one that handles empty. Such an adverb would, I'm anticipating, be quite a mess to write and read, though, much worse than the corrected version of powerSet I was complaining about earlier. Do situations like this indicate that the problem is best thought through again, so that a solution can be written that handles the whole domain in a consistent manner? Or are there ways of moving "adjustments" (like I've underlined) out of the way without obscuring them? Or should we just accept the apparent messiness of such things as indications of actual complexity in the problem domain? (In the case of this example, it does not seem to be true that these complications are inherent to the domain.) -- Tracy ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
