Leaving out the details of the many little obscure functions, what I was able 
to figure put is that
 - you have a C main app, where you 
 - define function sum (of int array returning int scalar) and pass it to J
 - form int array and pass it to J
 - invoke sum over array in J
 - return result to C

Right?

Oleg Kobchenko


On Jul 17, 2007, at 9:43 PM, "Jack Andrews" <[EMAIL PROTECTED]> wrote:

oleg wrote:
could you just provide a simple concrete use case or two
with actual function signatures on all layers involved.

here's my use case, with header file defining the API.
i'm working on implementing the API given the current C API.
documentation on the API is available here:
http://kx.com/a/k/connect/c/CandK.txt

J sum(J x)
{int z=0,i=0;assert(x->t==4&&x->r==1);
for(;i<x->s[0];i++)z+=x->d[i];return gi(z);
}
main()
{cd(jsj("",0));
sfn("sum",(J(*)(void))sum,1);
{C b[99];while(gets(b))
{J r=jsj(b,0);
 if(Nt==r->t&&NULL!=r->d)eO("! %s\n",r->d);else show(r);
 cd(r);
}}}

header file:
/* http://kx.com/a/k/connect/c/k20.h */
#define R return
#define O printf
#define Z static
#define DO(n,x) {I i=0,_i=(n);for(;i<_i;++i){x;}}
typedef int I;typedef double F;typedef char C;typedef C*S;
typedef struct j0{I c,t,r,*s,*d;}*J;

/* atom accessors, e.g. Ji(x)=2 */
#define Ji(x) (*JI(x))
#define Jf(x) (*JF(x))
#define Jc(x) (*JC(x))
#define Js(x) (*JS(x))
/* list accessors, e.g. JF(x)[i]=2.0 */
#define JI(x) ((I*)((x)->d))
#define JF(x) ((F*)((x)->d))
#define JC(x) ((C*)((x)->d))
#define JS(x) ((S*)((x)->d))

#ifdef __cplusplus
extern "C" {
#endif

extern S sp(S); /* symbol from phrase */

/* atom generators, e.g. gi(2),gf(2.0),gc('2'),gs(sp("2")) */
extern J gi(I),gf(F),gc(C),gs(S),gn(void);

/* list generator (t as in 4::), e.g. gtn(-1,9) integer vector */
extern J gtn(I t,I n);

/* phrase (-3=4::) generators, e.g. gp("asdf");C*s;gpn(s,4); */
extern J gp(S),gpn(S,I);

/* error, e.g. if(x->t!=-1)return jerr("need integer vector");*/
extern J jerr(S),gsj(S,J),gnj(I,...),ci(J),jsj(S,J),jap(J*,void*);
extern I cd(J),jd(I),dj(I),scd(I),sdf(I,I(*)(void)),sfn(S,J(*)(void),I);

#ifdef __cplusplus
}
#endif
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm



       
____________________________________________________________________________________
Building a website is a piece of cake. Yahoo! Small Business gives you all the 
tools to get online.
http://smallbusiness.yahoo.com/webhosting 
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to