[Pyrex] A couple of questions about pyrex

Yingjie Lan lanyjie at yahoo.com
Wed May 13 01:08:10 CEST 2009


--- On Wed, 5/13/09, Robert Bradshaw <robertwb at math.washington.edu> wrote:

> From: Robert Bradshaw <robertwb at math.washington.edu>
> Subject: Re: [Pyrex] A couple of questions about pyrex
> To: lanyjie at yahoo.com
> Cc: "Franck Pommereau" <pommereau at univ-paris12.fr>, pyrex at lists.copyleft.no
> Date: Wednesday, May 13, 2009, 2:48 AM
> On May 12, 2009, at 3:33 PM, Yingjie Lan wrote:
> 
> >
> > --- On Tue, 5/12/09, Franck Pommereau
> <pommereau at univ-paris12.fr>  
> > wrote:
> >
> >> From: Franck Pommereau
> <pommereau at univ-paris12.fr>
> >> Subject: Re: [Pyrex] A couple of questions about
> pyrex
> >> To: lanyjie at yahoo.com
> >> Cc: "Stefan Behnel"
> <stefan_ml at behnel.de>, pyrex at lists.copyleft.no
> >> Date: Tuesday, May 12, 2009, 8:15 PM
> >>> Think further down the road after that is
> done,
> >>> if some day we decided to use 'cdef
> class' for
> >>
> >>> private class definitions
> >>
> >> I don't think that cdef should be interpreted
> as
> >> private. But it means
> >> that what follows is a native object (ie,
> implemented in C)
> >> instead of a
> >> Python object.
> >
> > Sure, I am talking in the sense that
> > native = private (invisible to python)
> > pythonic = public (visible to python)
> 
> But cdef already has a (widely used) meaning.

That's true, and cdef defines something invisible
to python except for the 'cdef class', according
to my knowledge from the language documentation.
But correct me if I am wrong.

> 
> >
> >>
> >> So if you cdef a type, a variable or a function,
> there is
> >> no way to
> >> access it from Python because C and Python have
> different
> >> conventions
> >> for such objects (eg, Python uses name bindings in
> >> environment and has
> >> no proper notion of variable, and calling
> conventions are
> >> different also).
> >>
> >> On the other hand, if you cdef a class, there is
> no way to
> >> see it as a
> >> class from C because there is no such notion here.
> But
> >> anyway you get a
> >> class implemented in C, which is considered a
> builtin class
> >> by Python.
> >
> > Right now, as Stefan already said it, we don't
> support
> > native/private class yet. But, if in the future we
> choose
> > to do so, 'cdef class' would be the ideal
> syntax.
> 
> It seems "private class" would be more ideal,
> which could apply to  
> cdef classes, non-cdef classes, and all other kinds of
> declarations.

I would not recommend 'private class' for two reasons:

1. If you use 'private', then you might also use 'public',
etc, which makes things complicated.

2. Here we are actually not talking about a 'privateness'
in the broad sense, but rather in a very very specific 
sense: that is, only private to python. Such a private
class may still be visible in pyrex code/file.

So, how do we achieve that? The answer is already there,
exactly the same way we distinguish 'cdef' and 'def' 
for function declarations. 'def' declare a function
visible to python, while 'cdef' declares an invisible one.

I like this way because if I speak something in 
another language that you won't understand and 
you would probably ignore it. So if we write in a
way mimics python, then we suppose python would
know it, otherwise, python won't know. Naturally.


yingjie



      



More information about the Pyrex mailing list