Intermediate J question 
Author Message
 Intermediate J question

I have written a dyadic J function:

func =. (stuff to calculate left arg to fred) fred"1 _

Now I find that I want to do the same thing, but calling a
different function than fred.  Is there a way to pass a function
name into a function?  I reckon I can do something by passing in
a character string and executing it, but that seems gross.

Henry Rich



Fri, 21 Mar 1997 23:14:02 GMT  
 Intermediate J question
Henry Rich:
: I have written a dyadic J function:
:    func =. (stuff to calculate left arg to fred) fred"1 _
: Now I find that I want to do the same thing, but calling a different
: function than fred.  Is there a way to pass a function name into a
: function?  I reckon I can do something by passing in a character
: string and executing it, but that seems gross.

You can pass a function's gerund as data.  For example, fred`'' is a
scalar that represents the function fred.  However, it's usually more
efficient to deal with building functions at parse time (as opposed to
execution time).  Thus, you might want to build a function builder (an
adverb) to do this:

func_builder =. '(stuff to calculate left arg to fred) x."1 _' :21

Usage:
  func =. fred func_builder
  gunc =. gred func_builder

--
Raul D. Miller           n =: p*q             NB. 9<##:##:n [.large prime p, q

                         NB.  public e, n, y
                         x -: n&|&(*&y)^:d 1  NB. 1=(d*e)+.p*&<:q



Fri, 21 Mar 1997 23:53:25 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. JS-EAI with *JS*-callback

2. js.exception 3279.js

3. prefs.js question

4. Win2K/JS/TCL/Apache Question: Max Textarea Value Size

5. More J Questions : Printing intermediate values of y.

6. NB. gray.js: a J verb that generates a grayscale postscript image from a 2d array

7. lapackTest.js

8. profile.js

9. J script file profile.js

10. JS valueOf() in RB ?

11. JS for functional programming?

12. JS for functional programming?

 

 
Powered by phpBB® Forum Software