You want an adverb:

gamma=: 1 : '] , u , u D. 1'

produces the requested verb (],q, (q D. 1)) when called. Then if t is given to 
(q gamma), it will execute the fork and give you an array of your three values.

Marshall

-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of Alex Gian
Sent: Thursday, December 09, 2010 7:53 PM
To: Programming forum
Subject: [Jprogramming] Verbs that take verbs as arguments (pt 2)

Sorry to plague you with more newbie questions, but I'm a little pressed for 
time here.

OK, for anyone familiar with Scheme/Lisp/λ-calculus etc, here's what I'm trying 
to do:

(define (gamma q)
  (lambda(t)
    (list t (q t) ((d1 q) t)))


In other words, I want to pass a monadic verb (call it 'q') to the 'gamma' 
verb/function  and I want the result to be a monadic verb/function that will 
accept a value ('t') and return a three elem array of rank 1 t, q t, q D.1 t

IOW, something like
testfunc =. gamma @ q
testfunc 1.1
  1.1 (q 1.1) ((q D.1) 1.1)

(In case anyone wonders why the weird questions, I am working through Sussman & 
Wisdom's SICM, and would like to try the code in parallel in J to compare the 
two notations.)

I suppose I am really trying to figure how J deals with anonymous functions.  
Where I am getting stuck is the scoping of the values of y (and x) in explicit 
definitions.

I /could/ do it as a dyad, but
gamma=: dyad : 'y,(x y),x D.1 y'
doesn't seem to work for me either, and I really would prefer monadic, kinda 
seeing how "currying" maps to J.






----------------------------------------------------------------------
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