How to Call a Go Program from Common Lisp -
i have go program cannot rewritten in common lisp efficiency reasons. how can run via common lisp?
options far:
1. cffi
using foreign function interface seems me "correct" way this. however, research did lead directly dead end. if winner, resources there learn how interface go?
2. sockets
leaving go program running time while listening on port work. if best way, i'll continue trying make work.
3. execute system command
this seems kinds of wrong.
4. unknown
or there awesome way haven't thought of yet?
it depends on want do, 1-3 viable options
1. cffi
to work need use ffi on both go , lisp side. need extern appropriate function go c functions, , call them using cffi lisp. see https://golang.org/cmd/cgo/#hdr-c_references_to_go on how extern function in go. in case create dynamically linkable library (dll or file) rather executable file.
2. sockets (ipc)
the second option run go program daemon , use form of ipc (such sockets) communicate between lisp , go. works if program long running, or if makes sense have server , 1 or more clients (the server lisp code go code). sockets in particular more flexible, write components in other languages or change languges 1 component without having change others long maintain same protocol. also, potentially run components on seperate hardware. however, using sockets may hurt performance. there other ipc methods available, such fifo files (named pipes), shm, , message queues, more system dependent sockets.
3. system command (subprocess)
the third way start sub-process. viable option, has caveats. first of all, behavior of starting sub process dependent both on lisp implementation , operating system. uiop smooths out lot of details implementation differences, great overcome. in particular, depending on implementation may or may not able run subprocess in parallel. if not have run seperate command every time want communicate go, means waiting process start every time need it. may, or may not able send input subprocess after starting it.
another option run command start go process, , communicate using sockets or other ipc, , running command stop process before closing lisp program.
personally, think using sockets attractive option, depending on needs, on of other options might better suited.
Comments
Post a Comment