Hi!
I have an old application which needs to call python.
The old app is written in allegro lisp.
I tried the following:
(defparameter hlib "c:\\winnt\\system32\\python22.dll")
(probe-file hlib)
(ct:defun-dll Py_Initialize()
:return-type :void
:library-name hlib
:entry-name "Py_Initialize")
(ct:defun-dll PyRun_SimpleString((s :char *))
:return-type :long
:library-name hlib
:entry-name "PyRun_SimpleString")
(Py_Initialize)
(setq foo "print 'foo'")
(PyRun_SimpleString (cref (ct:char *) foo 0))
But get:
"""
The first element (CREF (CHAR *) foo 0) of a function
application is not a function name
"""
What could be wrong. I am new to lisp
thomas
Thomas Guettler <···········@thomas-guettler.de> writes:
> Hi!
>
> I have an old application which needs to call python.
> The old app is written in allegro lisp.
>
> I tried the following:
> (defparameter hlib "c:\\winnt\\system32\\python22.dll")
It's be better to say
(defparameter *hlib* (parse-namestring "c:\\winnt\\system32\\python22.dll"))
> (probe-file hlib)
This will just return the above pathname or NIL.
> (ct:defun-dll Py_Initialize()
> :return-type :void
> :library-name hlib
> :entry-name "Py_Initialize")
> (ct:defun-dll PyRun_SimpleString((s :char *))
> :return-type :long
> :library-name hlib
> :entry-name "PyRun_SimpleString")
>
> (Py_Initialize)
> (setq foo "print 'foo'")
> (PyRun_SimpleString (cref (ct:char *) foo 0))
>
> But get:
> """
> The first element (CREF (CHAR *) foo 0) of a function
> application is not a function name
> """
After your setting up of your Python Library you have ended up with a
function called
PyRun_SimpleString
(Note that ct:defun-dll may not be the best way to achieve this)
You are calling the above function of the value that the macro CREF.
However, note that CREF is in the CT package and that you may or may
not have that symbol available in your code snippet. Try putting the
fully qualified name in your code: CT:CREF.
> What could be wrong.
(with-sarcasm ()
(print "Wanting to use Python?"))
> I am new to lisp
Then stick with it. Rewrite the Python stuff in a better language and
live happier everafter.
Cheers
--
Marco Antoniotti ========================================================
NYU Courant Bioinformatics Group tel. +1 - 212 - 998 3488
719 Broadway 12th Floor fax +1 - 212 - 995 4122
New York, NY 10003, USA http://bioinformatics.cat.nyu.edu
"Hello New York! We'll do what we can!"
Bill Murray in `Ghostbusters'.
Marco Antoniotti wrote:
> Thomas Guettler <···········@thomas-guettler.de> writes:
>
>
>>Hi!
>>
>>I have an old application which needs to call python.
>>The old app is written in allegro lisp.
>>
>>I tried the following:
>>(defparameter hlib "c:\\winnt\\system32\\python22.dll")
>
>
> It's be better to say
>
> (defparameter *hlib* (parse-namestring "c:\\winnt\\system32\\python22.dll"))
>
>
>>(probe-file hlib)
>
>
> This will just return the above pathname or NIL.
>
>
>>(ct:defun-dll Py_Initialize()
>> :return-type :void
>> :library-name hlib
>> :entry-name "Py_Initialize")
>>(ct:defun-dll PyRun_SimpleString((s :char *))
>> :return-type :long
>> :library-name hlib
>> :entry-name "PyRun_SimpleString")
>>
>>(Py_Initialize)
>>(setq foo "print 'foo'")
>>(PyRun_SimpleString (cref (ct:char *) foo 0))
>>
>>But get:
>>"""
>>The first element (CREF (CHAR *) foo 0) of a function
>>application is not a function name
>>"""
>
>
> After your setting up of your Python Library you have ended up with a
> function called
>
> PyRun_SimpleString
>
> (Note that ct:defun-dll may not be the best way to achieve this)
>
> You are calling the above function of the value that the macro CREF.
> However, note that CREF is in the CT package and that you may or may
> not have that symbol available in your code snippet. Try putting the
> fully qualified name in your code: CT:CREF.
>
>
>>What could be wrong.
>
>
> (with-sarcasm ()
> (print "Wanting to use Python?"))
>
>
>>I am new to lisp
>
>
> Then stick with it. Rewrite the Python stuff in a better language and
> live happier everafter.
(begin-troll ()
(print "But ? There is *no* better language than Python !!!?"))
laotseu
Thomas Guettler <···········@thomas-guettler.de> writes:
> Hi!
>
> I have an old application which needs to call python.
> The old app is written in allegro lisp.
>
> I tried the following:
> (defparameter hlib "c:\\winnt\\system32\\python22.dll")
> (probe-file hlib)
> (ct:defun-dll Py_Initialize()
> :return-type :void
> :library-name hlib
> :entry-name "Py_Initialize")
> (ct:defun-dll PyRun_SimpleString((s :char *))
> :return-type :long
> :library-name hlib
> :entry-name "PyRun_SimpleString")
>
> (Py_Initialize)
> (setq foo "print 'foo'")
> (PyRun_SimpleString (cref (ct:char *) foo 0))
>
> But get:
> """
> The first element (CREF (CHAR *) foo 0) of a function
> application is not a function name
> """
>
Apart from what I said in my previous response, given ACL FFI
interface manuals, you should be able to just say
(PyRun_SimpleString "print 'foo'")
Cheers
--
Marco Antoniotti ========================================================
NYU Courant Bioinformatics Group tel. +1 - 212 - 998 3488
719 Broadway 12th Floor fax +1 - 212 - 995 4122
New York, NY 10003, USA http://bioinformatics.cat.nyu.edu
"Hello New York! We'll do what we can!"
Bill Murray in `Ghostbusters'.
Thomas Guettler wrote:
>
> I have an old application which needs to call python.
> The old app is written in allegro lisp.
>
This is how I call Python programs from Lisp in Unix.
The short (two line) test Python program (ltest.py) is:
#!/bin/usr/env python
print "Hello World"
In Lisp I call the program with run-shell-command:
LISP(2): (setq lout
(excl:run-shell-command "ltest.py"
:output :stream
:wait nil))
#<EXCL:INPUT-TERMINAL-STREAM fd 15 @ #x35888f52>
LISP(3): (read-line lout)
"Hello World"
NIL
With Windows you will probably need to use "python ltest.py"
as the run-shell-command.
Thanks,
Jeff Sandys