[clpython-devel] strange behaviour of python and mixed interpreters
Willem Broekema
metawilm at gmail.com
Thu Apr 14 22:24:00 UTC 2011
Hi Nik,
Thanks for trying it out, and for reporting these issues. Enabling the mixed
mode sets a custom *readtable* which means all input is caught and treated
specially. This might very well clash with what Slime expects, I have not
tested that. Of course it *should* work fine under Slime one day...
Without testing it, I suppose (double 4) fails because the symbol DOUBLE is
unaffected by the "def double ..". The lower-case symbol should work:
(|double| 4). The docs are based on the behavior in Allegro in Modern
mode. Perhaps the mixed-mode should have parameters to control case, so
cross-referencing Python and Lisp objects by default does "the right thing".
Thanks again for the reports, I'll work on them.
- Willem
On Sun, Apr 10, 2011 at 4:27 PM, Nitralime <nitralime at googlemail.com> wrote:
> *Hi folks!*
>
> I have installed clpython recently and encountered some problems
> while playing around with the provided interpreter modes.
>
> Here is a sample SLIME session
>
> --------------------------------------------------------------------------------
> ; SLIME 2011-01-28
> *CL-USER> (ql:quickload :clpython)*
> To load "clpython":
> Load 1 ASDF system:
> clpython
> ; Loading "clpython"
> .........
> CLPython quick start guide:
> Run a string of Python code: (CLPYTHON:RUN "for i in range(4):
> print i")
> Run a Python file: (CLPYTHON:RUN
> #p"~/example/foo.py")
> Start the Python "interpreter" (REPL): (CLPYTHON.APP.REPL:REPL)
> To start mixed Python/Lisp input mode:
> (CLPYTHON.PARSER:ENTER-MIXED-LISP-PYTHON-SYNTAX)
> Run the test suite: (ASDF:OPERATE 'ASDF:TEST-OP
> :CLPYTHON)
>
> (:CLPYTHON)
>
> *CL-USER> (CLPYTHON.PARSER:ENTER-MIXED-LISP-PYTHON-SYNTAX)*
> ;; The mixed Lisp/Python syntax mode is now active: custom *readtable* is
> set.
> ;; Python variables will be interned in the #<PACKAGE "COMMON-LISP-USER">.
> ;; To exit the mixed mode: (CLPYTHON.PARSER:EXIT-MIXED-LISP-PYTHON-SYNTAX)
> ; No value
> *CL-USER> (+ 2 3)*
>
>
> --------------------------------------------------------------------------------
>
> At this point the SLIME doesn't return back!
> I tested it also using a python expression. The same behaviour!
> C-c C-c drops the session into dubugger which in turn is not responsive!
> To terminate it the whole process must be killed.
>
> Tab completion also leads to a hanging emacs!
>
>
> ###############################################################################
>
> In a linux console it behaves differently but not exactly
> as described in the documentation. Here is a sample session:
>
>
> --------------------------------------------------------------------------------
> *$ rlwrap sbcl*
> This is SBCL 1.0.47, an implementation of ANSI Common Lisp.
> More information about SBCL is available at <http://www.sbcl.org/><http://www.sbcl.org/>
> .
>
> SBCL is free software, provided as is, with absolutely no warranty.
> It is mostly in the public domain; some portions are provided under
> BSD-style licenses. See the CREDITS and COPYING files in the
> distribution for more information.
> ** (ql:quickload :clpython)*
> To load "clpython":
> Load 1 ASDF system:
> clpython
> ; Loading "clpython"
> .........
> CLPython quick start guide:
> Run a string of Python code: (CLPYTHON:RUN "for i in range(4):
> print i")
> Run a Python file: (CLPYTHON:RUN
> #p"~/example/foo.py")
> Start the Python "interpreter" (REPL): (CLPYTHON.APP.REPL:REPL)
> To start mixed Python/Lisp input mode:
> (CLPYTHON.PARSER:ENTER-MIXED-LISP-PYTHON-SYNTAX)
> Run the test suite: (ASDF:OPERATE 'ASDF:TEST-OP
> :CLPYTHON)
>
> (:CLPYTHON)
>
> ** (CLPYTHON.PARSER:ENTER-MIXED-LISP-PYTHON-SYNTAX)*
> ;; The mixed Lisp/Python syntax mode is now active: custom *readtable* is
> set.
> ;; Python variables will be interned in the #<PACKAGE
> "COMMON-LISP-USER">.
> ;; To exit the mixed mode:
> (CLPYTHON.PARSER:EXIT-MIXED-LISP-PYTHON-SYNTAX)
> * (+ 2 3)
>
> 5
> ** def double (n):*
> * return 2*n*
>
> #<CLOSURE (FLET CLPYTHON::|__main__.__main__/double|) {1002F8D129}>
> ** double (4)*
>
> 8
> ** (double 4)*
>
> ; in: DOUBLE 4
> ; (DOUBLE 4)
> ;
> ; caught STYLE-WARNING:
> ; undefined function: DOUBLE
> ;
> ; compilation unit finished
> ; Undefined function:
> ; DOUBLE
> ; caught 1 STYLE-WARNING condition
>
> debugger invoked on a UNDEFINED-FUNCTION in thread #<THREAD
> "initial thread"
> RUNNING
> {1002980D01}>:
> The function SB-ALIEN:DOUBLE is undefined.
>
> Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.
>
> restarts (invokable by number or by possibly-abbreviated name):
> 0: [ABORT] Exit debugger, returning to top level.
>
> (SB-KERNEL::UNDEFINED-FUN-ERROR-HANDLER
> #<unavailable argument>
> #.(SB-SYS:INT-SAP #X7FFFF69F7480)
> #<SB-ALIEN-INTERNALS:ALIEN-VALUE :SAP #X7FFFF69F7000 :TYPE (*
> (STRUCT
>
> SB-VM::OS-CONTEXT-T-STRUCT))>
> (21))
> 0] 0
>
> *
>
> --------------------------------------------------------------------------------
>
> The evaluation of "(double 4)" fails.
>
>
> ################################################################################
>
> There is also a problem with python repl:
>
> ; SLIME 2011-01-28
> *CL-USER> (ql:quickload :clpython)*
> To load "clpython":
> Load 1 ASDF system:
> clpython
> ; Loading "clpython"
> .........
> CLPython quick start guide:
> Run a string of Python code: (CLPYTHON:RUN "for i in range(4):
> print i")
> Run a Python file: (CLPYTHON:RUN
> #p"~/example/foo.py")
> Start the Python "interpreter" (REPL): (CLPYTHON.APP.REPL:REPL)
> To start mixed Python/Lisp input mode:
> (CLPYTHON.PARSER:ENTER-MIXED-LISP-PYTHON-SYNTAX)
> Run the test suite: (ASDF:OPERATE 'ASDF:TEST-OP
> :CLPYTHON)
>
>
> (:CLPYTHON)
> *CL-USER> (push "/usr/lib/python2.7" *clpython-module-search-paths*)*
> ("/usr/lib/python2.7")
>
> *CL-USER> (clpython:repl)*
> Welcome to CLPython, an implementation of Python in Common Lisp.
> Running on: SBCL 1.0.47
> REPL shortcuts: `:q' = quit, `:h' = help.
> Using 1 default module search paths set in *CLPYTHON-MODULE-SEARCH-PATHS*
> *>>> import os*
> ;; Parsing #P"/usr/lib/python2.7/os.py" into
> #P"/usr/lib/python2.7/os.py.lisp"
>
> ;; Error occured while reading input with the Python readtable:
> ;; UnexpectedEofError: Unexpected end of file (line 752).
> ;; Standard IO syntax (*readtable* etc) has been activated to enable
> debugging.
>
> --- Debugger window ----------------------------------
> UnexpectedEofError: Unexpected end of file (line 752).
> [Condition of type
> CLPYTHON.USER.BUILTIN.TYPE.EXCEPTION:|UnexpectedEofError|]
>
> Restarts:
> 0: [RETRY] Retry evaluating this top-level form in module `__main__'
> 1: [ERROR] Skip this top-level form in module `__main__'
> 2: [RETRY-REPL-EVAL] Retry the expression: "import os"
> 3: [RETURN-PYTHON-TOPLEVEL] Return to Python top level
> 4: [RETRY] Retry SLIME REPL evaluation request.
> 5: [*ABORT] Return to SLIME's top level.
> --more--
>
>
> Just for testing purpose I have commented the following code block in os.py
>
>
> -----------------------------------------------
> *.....
> 742 if not _exists("urandom"):
> 743 def urandom(n):
> 744 """urandom(n) -> str
> 745
> 746 Return a string of n random bytes suitable for cryptographic
> use.
> 747
> 748 """
> 749 try:
> 750 _urandomfd = open("/dev/urandom", O_RDONLY)
> 751 except (OSError, IOError):
> 752 raise NotImplementedError("/dev/urandom (or equivalent) not
> found")
> 753 try:
> 754 bs = b""
> 755 while n > len(bs):
> 756 bs += read(_urandomfd, n - len(bs))
> 757 finally:
> 758 close(_urandomfd)
> 759 return bs*
> -------------------------------------------------
>
> and tried the "import os" again and got the same error:
>
> --- Debugger window ----------------------------------
> UnexpectedEofError: Unexpected end of file.
> [Condition of type
> CLPYTHON.USER.BUILTIN.TYPE.EXCEPTION:|UnexpectedEofError|]
>
> Restarts:
> 0: [RETRY] Retry evaluating this top-level form in module `__main__'
> 1: [ERROR] Skip this top-level form in module `__main__'
> 2: [RETRY-REPL-EVAL] Retry the expression: "import os"
> 3: [RETURN-PYTHON-TOPLEVEL] Return to Python top level
> 4: [RETRY] Retry SLIME REPL evaluation request.
> 5: [*ABORT] Return to SLIME's top level.
> --more--
>
>
> The situation under Clozure is even worse! The mixed interpreter doesn't
> work
> neither in SLIME nor directly in linux console.The python repl behaviour is
>
> similar to that of SBCL.
>
> I'm using Clozure 1.6-r14468M and SBCL 1.0.47 on Linux 64bit.
> The installed version of clpython ist "clpython-20110219-git".
>
> Are these known issues or am I missing something here?
>
> Any feedback is very much appreciated!
>
> Regards
> Nik
>
>
>
>
>
>
> _______________________________________________
> clpython-devel mailing list
> clpython-devel at common-lisp.net
> http://common-lisp.net/cgi-bin/mailman/listinfo/clpython-devel
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/clpython-devel/attachments/20110415/8f588e53/attachment.html>
More information about the Clpython-devel
mailing list