[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-apl] using c libs in apl?

From: Christian Robert
Subject: Re: [Bug-apl] using c libs in apl?
Date: Tue, 7 Feb 2017 23:19:15 -0500
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0

I love that.

Of course it will possibly/eventually crash your APL session if you do the 
smallest error in your parameters definition.

"libffi" as mentioned by Elias is also a great possibility, already available 
by default on Fedora, CentOS-7, debian, ...

I just had to install libffi-devel to be able to run some successful tests in C.

all this is very promising.

My last struggle with this kind of thing is that I wanted a 
Quad-FIO['datetime'] (refused a year ago or so, but needed now)
able to return

  a) a float meaning the current time in milli or microsecond since epoch if 
called with arg=0.
  b) a Quad-TS array if called with 1 arg when arg>0 and assuming it's an epoch 
at milli/micro/seconds accuracy.
  c) a float when arg is an array of length 7, eg: in the Quad-TS style.

I ended up to write the function in C and call it via a wrapper function 
written in APL using FIO['popen'], FIO['read'] and FIO['pclose']

very painful, slow (it invoke calling an external program on each invocation), 
but it work pretty well.

what I really wanted at that time was an interface to "localtime()" and 
"gettimeofday()", the former using a r/w reference to a struct tm.

not easy to program the (libffi and/or the x15.c) wrappers to APL, I agree.


On 2017-02-07 12:30, Xiao-Yong Jin wrote:
It would be nice if one doesn't need to write wrappers and the APL system can 
do the
structure conversions within the APL interpreter.  In J, you can dlopen a 
and pass J values directly without writing and compiling C, see


and the relevant code is at


It would simplify using external libraries a lot.

On Feb 4, 2017, at 7:38 AM, Juergen Sauermann <address@hidden> wrote:


yes there is: native functions. You can load shared libraries and ⎕FX functions 
them to be called from APL code. The src/native directory contains a few 
that you can use as a starting point and to call your favourite library from 

Of course you need to provide wrappers from/to APL values to/from the data
structures expected or produced by the libraries.

Coming back to your other problems, if you do not like the terminal I/O of GNU 
APL, then
you can write your own one and call libapl from it. I have extended libapl 
recently, giving
you the full functionality of GNU APL without the specific ways how it handles 
terminal IO.

/// Jürgen

On 02/04/2017 02:52 AM, address@hidden wrote:
is there method for loading a c lib and using it in apl ?  cdecl?   like this 
in fpc?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]