About 2-3 weeks ago, I was struggling with monadic Raze and Henry pointed me
to his text, J for C programmers:

    http://www.jsoftware.com/help/jforc/more_verbs_for_boxes.htm

Now I'm not just trying to understand J, I'm trying to implement it. And I
dont know how I would manage without Henry's text. 

First he starts us out with a very simple example:

   ; 1 ; 2 3 4
1 2 3 4

Which made it easy for me to create a version of my raze procedure which did
not have to sweat all the fill details:

(define alob2   ; alob2 is a rank-1 array composed of an atom in a box and a
list in a box
  (rank-1
   (Box 1)
   (Box (rank-1 2 3 4))))
(mraze alob2) ; monadic raze on it...

 #(1 2 3 4)    ; yields a vector result


(define (mraze a)
  (let* ([unboxed-a (unbox-array a)]
         [unboxed-l (array->list unboxed-a)]
         [item-shapes (map item-shape unboxed-l)]
         [data-ranks (map my-array-rank unboxed-l)]
         )
    (if (all-equal? equal? item-shapes)
        (if (<= (apply max data-ranks) 1)
            (apply rank-1 (flatten (map array-items unboxed-l)))
            #f) ; placeholder for equal rank but data-rank > 1
        #t))) ; placeholder for unequal item-shapes

Then he increases the complexity just a bit by using higher-dimensioned
arrays:


   ; (i. 2 3) ; (i. 2 3) 
0 1 2
3 4 5
0 1 2
3 4 5

And then I simply fill in one of the placeholders in my function:


(define a (Integers (rank-1 2 3)))
(define b (Integers (rank-1 2 3)))
(define a-b (rank-1 (Box a) (Box b)))
(mraze a-b)

 #,(array vector ((0 . 3) (0 . 2)) ((0 1 2) (3 4 5) (0 1 2) (3 4 5))) ; same
output as J

(define (mraze a)
  (let* ([unboxed-a (unbox-array a)]
         [unboxed-l (array->list unboxed-a)]
         [item-shapes (map item-shape unboxed-l)]
         [data-ranks (map my-array-rank unboxed-l)]
         )
    (if (all-equal? equal? item-shapes)
        (if (<= (apply max data-ranks) 1)
            (apply rank-1 (flatten (map array-items unboxed-l)))
            (apply array-join '#() #f (flatten (map (lambda (a) (array-split
a 1)) unboxed-l))))
        #f))) ; final placeholder - for the case where shapes are not equal


And of course, he also provides some examples how to handle every major case
where the item shapes are not equal. So all I have to do to finish out my
function is emulate his cases for those.

But it would've been ultra-confusing to work straight from the dictionary.
And also very confusing to not have a gradual introduction to the
complexities of this verb.

It takes a lot to write a book as well as Henry did and it takes even longer
before anyone can realize how carefully put together this text is.

Thank you Henry

-- 
View this message in context: 
http://www.nabble.com/praises-to-the-fine-authorship-of-Henry-Rich-tf4747372s24193.html#a13574680
Sent from the J General mailing list archive at Nabble.com.

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to