funcB_B_ geomean_A_`'' ; data
do not use f. inside funcB.  f. will lose locale info

      From: 'Jon Hough' via Programming <programm...@jsoftware.com>
 To: programm...@jsoftware.com 
 Sent: Friday, September 1, 2017 1:09 AM
 Subject: Re: [Jprogramming] Passing class member gerund to verb in another 
locale
   
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

Reply via email to