I wrote: > There are also ways to use u without explictly inspecting or switching on > its nameclass, but these are use-case specific, obviously. > > If you post your fuller use-case or current adverb, we might be able > to help you minimize bookkeeping on the argument's nameclass.
I re-read your example: > '+: y' (1 : 'if. isNoun ''u'' do. u =. (13 : u) end. u ') 3 Here, you'd like to allow the user to specify either a verb directly, or the body of an explicit definition (a-la '12 * y') which you'll try to normalize to a tacit verb (using 13 :). In other words, you want to accept verbs or nouns and normalize all inputs to tacit verbs. That makes sense. Unfortunately, the tip I posted: > One common approach is 1 : 'stuff =. u"_ data' which will apply u to 'data' > if u is > a verb, or give 'stuff' the same value as u if the user passed in a noun. > Then you just deal with 'stuff' and forget about u . Pretty nice way to > let a user provide either a specific value (passing in a noun) or a way to > produce a desired value (passing in a verb). is not applicable, because you want to produce a verb instead of a noun, and your (potential) noun-processor is a conjunction, :, not a verb. Conjuctival phrases are harder to abstract than verbal phrases in J (because verbs are the most common kind of word and the focus of the language). That is, in the phase change from programming to meta-programming we must shed some weight to rise higher. A few of our favorite tools, though worthy and dependable, must be left behind. So, in this case, I think we will have to test u's nameclass (at least, all the ways I can think of test u's nameclass directly or indirecty [e.g. by catching syntax errors raised by 13 : ]). But maybe we can make the test a little more fluid; tied a little tighter to the consequences: lenient =: 1 : 'u =. u 1 :(''u'' ,~ ''13 : '' #~ noun=nc<''u'')' +: lenient +: '+: y' lenient +: ;) -Dan ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm