Is there a simple way to use Python libraries from

2019-04-04 13:05发布

One thing I really miss when writing Common Lisp code is access to Python libraries, both standard library and third party modules. CLPython provides a limited subset of Python functionality which precludes the use of most libraries, so that's not really useful to me. I would like to be able to call Python code from Common Lisp such that it runs in a Python VM like CPython or PyPy.

5条回答
别忘想泡老子
2楼-- · 2019-04-04 13:47

I know this are different languages, but why don't you give Clojure and Jython a try :) :)

Perhaps you find your self exactly where you want.

查看更多
唯我独甜
3楼-- · 2019-04-04 13:48

You may want to try burgled-batteries, a bridge between Python and Lisp (FFI bindings, etc.).

From the description, "burgled-batteries provides a shim between Python (specifically, the CPython implementation of Python) and Common Lisp."

查看更多
干净又极端
4楼-- · 2019-04-04 13:51

One solution is python-on-lisp. It should be ASDF-installable. It hasn't been maintained or updated for a couple years, so there may be something better available.

查看更多
祖国的老花朵
5楼-- · 2019-04-04 13:59

I would suggest writing an "exposer" interface for your code that takes text and writes text such that you can call it on the command line. Ideally, with a typical STDIN | STDOUT approach.

I believe that is typically the best approach for non-performance applications.

查看更多
爱情/是我丢掉的垃圾
6楼-- · 2019-04-04 14:00

You might like async-process, which allows to send code to a running Python process. It is used in the Lem editor.

Example use:

CL-USER> (ql:quickload :async-process)
To load "async-process":
  Load 1 ASDF system:
    async-process
; Loading "async-process"
..................................................
[package async-process].
(:ASYNC-PROCESS)
CL-USER> (in-package async-process)
#<PACKAGE "ASYNC-PROCESS">
ASYNC-PROCESS> (create-process "python")
#.(SB-SYS:INT-SAP #X7FFFEC002830)
ASYNC-PROCESS> (defparameter p *)
#.(SB-SYS:INT-SAP #X7FFFEC002830)
ASYNC-PROCESS> (process-receive-output p)
"Python 2.7.13 (default, Nov 24 2017, 17:33:09) 
[GCC 6.3.0 20170516] on linux2
Type \"help\", \"copyright\", \"credits\" or \"license\" for more information.
>>> "
ASYNC-PROCESS> (process-send-input p "1+1
")
; No value
ASYNC-PROCESS> (process-receive-output p)
"1+1
2
>>> "
查看更多
登录 后发表回答