Newsgroups: comp.lang.apl
Path: watmath!watserv2.uwaterloo.ca!torn!utnut!cs.utexas.edu!uunet!decwrl!csus.edu!sfsuvax1.sfsu.edu!vpcsc4
From: vpcsc4@sfsuvax1.sfsu.edu (Emmett McLean)
Subject: Calling J from C : a simple example
Message-ID: <1993Apr25.204841.12965@csus.edu>
Sender: news@csus.edu
Organization: San Francisco State University
Date: Sun, 25 Apr 1993 20:48:41 GMT
Lines: 35

/* Simple example C program which calls J.
   Prints the first 5 Hermite polynomals 
   emclean@vax1
   name this file main.c and use the makefile I posted in the
   earlier post on calling C from J.
*/

#include <stdio.h>
#include <string.h>
#include "lj.h"

C jc(k,f1,f2)I k;AF*f1,*f2;{}

main(){A p; int *d; int i,j;
 jinit();
 /* define verb for hermite interation */
 (void) jx("hi=., (-/@(,&0@(<:@+:@# * ]) ,: 0&,)@{: - ,&0@(*:@<:@# *])@{:@}:)");

 /* assign p the struct of type A containing 1st 5 hermite polynomials */
 p = jx("hi ^:(5-2) (2 2 $ 1 0 1 _1)");

 /* get values out of the type A data structure and cast to integers
    (cast to doubles in other applications where doubles are expected) */
 d = (int*) AV(p); 

 /* we could output the data directly from p using jpr but lets do it this
    way so we can see what we're getting */
 for(i=0;i<=4;i++){
  printf("\n");
   for(j=0;j<=4;j++)
   printf("%6d",*d++);
 }
 printf("\n");
}

