This looks to be a pretty useful thing to have on hand, though I don't have a use for it at the moment. I think I might have written some things differently if fl had been available.
Henry Rich > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Dan Bron > Sent: Tuesday, January 02, 2007 9:22 PM > To: 'Programming forum' > Subject: [Jprogramming] Fix local names > > For those interested, I've created an adverb like f. which > fixes only local names: > > NB. Put the following lines in a script (separate file): > local =. + > global =: - > r =. global local % > > f =: r fl > g =: (global local r global -) fl > NB. End of script > > load 'name_of_your_script.ijs' > > f > global + % > > g > global + (global + %) global - > > require 'strings' > > # 1 : ('w=.[: u&.> cut';'w ') > |value error: w > > # 1 : ('w=.[: u&.> cut';'w f.') > [: #&.> 3 : ''' ''&$: :([: -.&a: <;._2@,~) y' :(4 : 'x > '' ''&$: :([: -.&a: <;._2@,~) y') > > # 1 : ('w=.[: u&.> cut';'w fl') > [: #&.> cut > > > See the postscript for the current definition. Right now, > you can only my adverb to fix verbs, because string arguments (a la > 'name' fl ) are not yet supported. Should anyone show > interest, when JAL officially comes out, I'll supply a better written > and documented version as an addon. > > -Dan > > PS: See > http://www.jsoftware.com/svn/DanBron/trunk/environment/namesco > pe.ijs for a script complete with comments. > > fl =: `({.;:'Peel') (resolve`) (`:6) (5!:0) > resolve =: >@:peel^:({.@:ns_isLOCAL :: 0:) L: 0^:_ > Peel =: 1 : 'peel ''u'' ' NB. ' > {. u`[ ' > peel =: [: ". '{. 5!:1 {. ;: '' ' , '''' ,~ ] > > ns_isLOCAL =: 2 = ns > ns =: #.@:nameScope > nameScope =: (( (~: ,. *.&:(~:&_1)) ({~ > i.&1@:~:&_1 <. _1 + #)"1 )&: > (([ #!._1^:_1: 15!:6@:# )"1~ _1 < nc) > [: ;&.> @:{ 1j1 1j1 > #!.(<<'_') ] ,&< (, > |.@:copath)@:coname@:(''"_) )@: > (;:^:(0 = L.)) > > > Caveat: You'll notice the current version of nameScope > uses the undocumented foreign 15!:6 . It's not __neccesary__ to do > it this way, but the "supported" methods (that I can think > of) are much messier. Again, if there's interest, I can change this. > > As it stands, however, the definition uses the undocumented > foreign, which means there is no guaruntee that it'll work in future > versions of J (though 15!:6 is unlikely to be revoked > because it's required for JMF). Also, since the 15!: > family mucks with > memory, a small slip (in either its implementation or its > use) can crash J. I don't think there are circumstances > under which fl > will crash J, but you've been warned. > > ---------------------------------------------------------------------- > For information about J forums see > http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
