bendudson / py4cl

Call python from Common Lisp
Other
227 stars 31 forks source link

Turn .lisp scripts written with py4cl to .py scripts #47

Closed DurhamSmith closed 3 years ago

DurhamSmith commented 3 years ago

Hello, I am wondering if there is any way to generate .py files from lisp code that that implements the desired python script using py4cl.

digikar99 commented 3 years ago

If you mean converting from lisp-code to equivalent python script, nope; the closest I know of is cl4py that one can use to write a python script which can use lisp.

DurhamSmith commented 3 years ago

Thanks, sorry for my ambiguous first message. What I am looking for is something that can take code, like the following:

(ql:quickload :py4cl)

(py4cl:import-module "numpy" :as "np")
(py4cl:import-module "scipy.integrate" :as "integrate")

;; Integrate some ODEs
(defparameter *data*
  (integrate:odeint 
   (lambda (y time) 
     (vector (aref y 1)       ; dy[0]/dt = y[1]
             (- (aref y 0)))) ; dy[1]/dt = -y[0]
   #(1.0 0.0)   ; Initial state
   (np:linspace 0.0 (* 2 pi) 20)))  ; Vector of times

; (array-dimensions *data*) => (20 2)

;; Make a plot, save and show it in a window
(py4cl:import-module "matplotlib.pyplot" :as "plt")

(plt:plot *data*)
(plt:xlabel "Time")
(plt:savefig "result.pdf")
(plt:show)

and turn it into a pure python script.

digikar99 commented 3 years ago

I don't know of anything that can do that. And, due to the semantic/power differences, it'd also be difficult to do that in general. I can imagine some subset of lisp being transpiled to python, perhaps using hylang as an intermediate; but don't know of anything that is available today.

DurhamSmith commented 3 years ago

Ok, thanks for the prompt response!