[clpython-devel] Fwd: Choice of Common Lisp

Willem Broekema metawilm at gmail.com
Sun Dec 17 10:39:41 UTC 2006


Link to message:
http://groups.google.com/group/comp.lang.python/msg/fbfdc12acddc0f3f

---------- Forwarded message ----------
From: metawilm at gmail.com <metawilm at gmail.com>
Date: Dec 15, 2006 8:23 PM
Subject: Re: CLPython (was Re: merits of Lisp vs Python)
To:


Paul Rubin wrote:
> I thought it was of some interest though I'm a little surprise by the
> choice of CL rather than Scheme as a target.

In many aspects Python is a subset of CL. In CLPython, exceptions are
Lisp conditions with a custom metaclass (strictly spoken not portable
CL), Python (meta)classes are CLOS classes, methods are implemented
using hashtables and functions and CLOS generic functions, strings and
numbers have direct equivalents, hash tables implement dicts, Python
functions are funcallable CLOS instances, tuples and lists are Lisp
lists and vectors, generators are closures. Thus a great part of
implementing CLPython consisted of connecting already existing dots. I
found that quite amazing.

> I'm still not sure about the mapping of Python strings to Lisp strings.
> What happens with the following in CLPython?
>
>   a = 'hello'
>   a[0] = 'H'   # attempt to change first letter to upper case

As CLPython mirrors Python semantics, this results in a TypeError. The
internal representation of an immutable Python string is a mutable Lisp
string, but there is no way you can actually modify it from within
CLPython.

Now in some cases modifying strings is dangerous (e.g. when stored in
an instance dict to represent an attribute), but in other cases it can
be completely safe. And modifying strings is a normal Lisp feature, so
it sounds strange to disallow it at all times. Maybe there should be a
way for the user to declare that he knows what he is doing, and does
not want the Python implementation to be "crippled" w.r.t. the host
language. Normally you start the CLPython interpreter using (repl);
maybe something like this would allow dangerous statements:

  (let ((*strict-python-semantics* nil))
    (repl))

Oh, and there is actually one way to modify Python strings in the
interpreter, namely using Lisp commands:

PYTHON(12): (repl)
[CLPython -- type `:q' to quit, `:help' for help]
>>> s = "abc"
'abc'
>>>  (setf (aref _ 0) #\x)
#\x
>>> s
'xbc'
>>> type(s)
#<class PY-STRING @ #x10575342>
>>> type(s) == str
1
>>> s
'xbc'
>>>  (inspect _)
A NEW simple-string (3) "xbc" @ #x11548f6a
   0-> The character #\x [#x0078]
   1-> The character #\b [#x0062]
   2-> The character #\c [#x0063]
[1i] PYTHON(13): :ptl
>>>



More information about the Clpython-devel mailing list