Martin,
My "solution" was an amusing lark, and was an abuse of JMF. The
results are implementation-dependent, and should not be used.
Chris Burke provided a locale-based solution which seems exactly what
your solution aspires to:
http://www.jsoftware.com/pipermail/programming/2006-January/000636.html
Note the critical use of parentheses on the last line:
3 : (n,'=:',n,'+y.')
These are required because : (colon) is a conjunction and therefore
has higher precedence than any verb. So with:
3 :".'Xc,''=:'',Xc,''+y'''
you're really saying (3 : ".) ... instead of 3 : (". ...) as you
intend. Note also the ". isn't required (even if 3 : ". worked as
you expected syntatically, it wouldn't do what you wanted
semantically. You only need the , (catenates)).
Oleg Kobchenko improved Chris' solution by removing the requirement
for globals:
http://www.jsoftware.com/jwiki/FrequentlyAskedQuestions/LexicalClosure
hence it is impossible for any other entity in J to interfere with the
operation of verbs derived from Oleg's adverb (as was specified by
Graham in the original challenge).
And if line count is very important to you, Oleg's solution can be
reduced to a single line:
accgen=:1 :'a&(4 :''n__x=:n__x+y'')2 :''u''n__a=:m[a=.18!:3$~0'
which is silly and unreadable but acheives its end.
By the way, Oleg's solution IS up on the wiki:
http://www.jsoftware.com/jwiki/FrequentlyAskedQuestions/LexicalClosure
But apparently all your wiki-searches are coming up with my "solution"
instead:
http://www.jsoftware.com/jwiki/DanBron/Temp/LexicalClosure
which probably means I should remove it (and I will), so that others
are not led astray. But that also means whatever you're searching for
IS on my page, but NOT on the "canonical" page. For what did you
search? What search strings did you enter?
We should optimize the canonical page to come up at the top of the
results for such queries. And maybe the page should be moved from
/FrequentlyAskedQuestions/ to Henry Rich's /Guides/LanguageFAQ ? Is
this appropriate material for that page?
-Dan
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm