C API - null symbols

linking from Stack Overflow here. Can anyone help me out?

Not an expert on this matter, but can you try comparing the values instead? Also, may need to cast explicitly to symbol:

K test (K x) { K ns = ks((S)""); if (abs(x->t) != KS) { R krr((S)"type"); } if (x->t > 0) { K res = ktn(KB,x->n); for (int i=0;i<x->n;++i){ if (ks(kS(x)[i])->s == ns->s) { kG(res)[i] = 1; } else { kG(res)[i] = 0; } } R res; } else { if (x->s == ns->s) { R kb(1); } else { R kb(0); } }}

Not an expert on this matter, but can you try comparing the values instead? Also, may need to cast explicitly to symbol:

K test (K x) { K ns = ks((S)""); if (abs(x->t) != KS) { R krr((S)"type"); } if (x->t > 0) { K res = ktn(KB,x->n); for (int i=0;i<x->n;++i){ if (ks(kS(x)[i])->s == ns->s) { kG(res)[i] = 1; } else { kG(res)[i] = 0; } } R res; } else { if (x->s == ns->s) { R kb(1); } else { R kb(0); } }}

?

Hi Ethel,

I responded to the post.

You only care about the the underlying char array in each case so you need to compare this rather than the entire k object

Also ensure any k objects are dereferenced when finished with

Thanks

if you make ‘ns’ static, you don’t need to allocate it each time and then remember to free it afterwards.

this requires the use of g++ instead of gcc (and also the ‘extern “C”’ wrapper).

i see you are using some of the macros in k.h.  if we go ‘all-in’, we can also remove the stinking loops and conditionals. the result is, imho, much easier to read:

extern “C” {
K1(test) {
  ZK ns = ks((S)“”);
  K r;
 
  SW(xt) {
    CS(-KS,r = kb(xs==ns->s));
    CS( KS,r = ktn(KB,xn); DO(xn,kG(r)[i] = ns->s==xS[i]));
    CD:    r = krr((S)“type”);
  }
  R r;
}
}

here are a few tests:

q)x:``foo

q)test x
10b
q)test each x
10b
q)test enlist x
'type
  [0]  test enlist x
       ^