Thanks. To stop things getting very complicated and convoluted I opted for a solution where I add a second verb to locale B, which accepts an object reference parameter, and wraps the object reference's verb (i.e myVerb__myA) in a wrapper verb. Then passes this to the original B verb. This way, there is flexibility in that I can use B's verbs with either objects or standalone verbs.
coclass 'A' create=: 3 : 0 d=:y ) geoMean=: 3 : 0 (#%:(*/)) y ) myVerb=: 3 : 0 ((geoMean ) ; (+/%#)) y ) getAvg=: 3 : 0 data=.y funcB2_B_ (coname ''); data ) cocurrent 'B' NB. accepts the object ref as param. NB. helper verb, for special case of NB. classes with a member verb called myVerb. funcB2=: 3 : 0 'obj data'=: y verb=. 3 : ' myVerb__obj y' funcB ((verb f.) `'');data ) NB. More general verb, accepts any verb NB. (assuming verb is callable from this locale) funcB=: 3 : 0 'vrb data' =: y f=: vrb `:6 f data ) -------------------------------------------- On Fri, 9/1/17, Raul Miller <rauldmil...@gmail.com> wrote: Subject: Re: [Jprogramming] Passing class member gerund to verb in another locale To: "Programming forum" <programm...@jsoftware.com> Date: Friday, September 1, 2017, 4:33 PM I have occasionally found it useful to have a mechanism which (using the terminology of http://www.jsoftware.com/help/dictionary/dicti.htm ) makes a non-locative name into a locative name. Something along these lines: makelocative=:4 :0 if. ({: */&(+./) }:)'_'=x do. x else. x,'_',y,'_' end. ) (That said, please note that more work needs to be done if you want to support indirect locatives as arguments. Otherwise you'll get an ill formed name error if you try to do that. Alternatively you could remove the if statement if you are guaranteed that x will not already be a locative and you want to treat "x is already a locative" as an error case.) I hope this helps, -- Raul On Fri, Sep 1, 2017 at 1:09 AM, 'Jon Hough' via Programming <programm...@jsoftware.com> wrote: > I forgot to add a definition of funcB > > cocurrent 'B' > > funcB=: 3 : 0 > 'vrb data' =: y > f=: vrb `: 6 NB. vrb is the gerund > f data NB. call f. This creates the error. > ) > > > -------------------------------------------- > On Fri, 9/1/17, 'Jon Hough' via Programming <programm...@jsoftware.com> wrote: > > Subject: [Jprogramming] Passing class member gerund to verb in another locale > To: "Programming Forum" <programm...@jsoftware.com> > Date: Friday, September 1, 2017, 2:03 PM > > My problem is, I have a class 'A' say. > and I have a locale 'B'. > > A contains several verbs. I would like > to pass a verb (or gerunds of the verbs), let's call it > myVerb, to some verb in B. However, this creates a problem, > as > when the B verb tries to call myVerb it > cannot find it, being in a different locale. i.e. I get a > value error. I attempted to use fix (f.) to get myVerb > explicitly, but this only > works if myVerb does not contain any > other verbs from A. > > This is the contrived example, that is > essentially the same as my real problem, but stripped of > superfluous things: > > NB. A is some class with several > verbs. > coclass 'A' > > > create=: 3 : 0 > d=:y > ) > > NB. some verb in A > geoMean=: 3 : 0 > (#%:(*/)) y > ) > > > NB. I want to pass this to another verb > in another locale. > NB. Note that it calls geoMean. > myVerb =: 3 : 0 > ((geoMean f.) ; (+/%#)) y > ) > > > NB. calling a verb in B > getAvg=: 3 : 0 > data=.y > funcB_B_ ( myVerb f. `''); data > ) > > NB. create my instance of A > myA =: 0 conew 'A' > NB. call myVerb. No problem here! > myVerb__myA 1 2 3 > NB. pass myVerb to funcB_B_ > getAvg__myA 1 2 3 > NB. this gives an error > |value error: geoMean > | ((geoMean > f.);(+/%#))y > > > > Solutions: > (1) One solution is to make funcB_B_ a > conjunction / adverb. But in reality, I want to send several > verbs to funcB together. > (2) Another solution is to send the > instance reference of A to funcB (i.e. just send the whole > of myA to funcB). But I would prefer not to send the whole > object, as it then makes B less flexible, because I may want > to call funcB_B_ without the need for a class instance, just > a standalone verb. > (3) Another solution is to not call any > other verbs of myA inside myVerb__myA. This is not a > realistic solution as A could be quite complicated. > > > Is there a better way? > > Just to explain my motivation, I am > trying to replicate the functionality most languages that > have first-class functions possess - to pass arbitrary > function(s) to > other functions and call them. > e.g. in Python > > # myVerb is a Python function, and > could be a member method of some class. someData is just > some data > def funcB (myVerb, someData): > return myVerb(someData, > someOtherData) > > Obviously J doesn't have first class > functions in this sense, but with gerunds, I was hoping to > be able to recreate the functionality. > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm