A 'Python like' language

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Zipher

    #76
    Re: A 'Python like' language

    [Mark Hann][color=blue]
    > Obviously Prothon is not Python compatible, so I have taken the liberty of
    > implementing many changes that have been imagined for the almost mythical
    > Python 3.0...[/color]

    Gee, my love of Python makes me feel a little guilty about looking at
    another language, but Prothon does look appealing. Classes really do
    start looking archaic... Would a threesome be out of the question?

    My Python3k suggestions for Prothon:

    --Take advantage of iterators early on for return values to avoid
    things like having both dict.items() and dict.iteritems( ).
    (Decorators add even larger possibilities for fresh syntax and other
    considerations. )

    --Choose "{:}" syntax for empty dict creation to reserve "{}" for
    sets. (Or: use "{}" for both, and do automatic "set-to-dict
    promotion" upon encountering a (key, value) assignment.)

    --Functions that return multiple, but unique, values should return a
    set, not a list, to communicate same (ex: dict.keys(), dir(), etc.).
    (Consider iterator caveat above, however.)

    Such functions often have surprising uses for set operations anyway.
    Consider, for example, using set operations on dir() to answer
    questions like Which parent functions/variables get re-assigned in the
    child class? or What new fns/vars does this child add?

    --Dict should inherit from Set.

    --No Dict.update(), since this is now identical with Set.__ior__()
    (i.e. d1 |= d2).

    Could follow Python's behavior with regard to key collisions (a matter
    of contentious debate if I remember), OR perhaps even better:

    --Dict object could contain optional "collision function attribute"
    that is called to resolve values on key collisions.

    Consider, for example, an easy Bag(Dict) object with said attribute
    assigned to "operator.a dd" for the union method(s). This would also
    maintain the >10x speed factor (in Python anyway) of using underlying
    C-implmentation rather that hand iteration through dicts.

    --With prothon's "immutabili ty" bit and other considerations, does the
    language need both tuples AND lists?

    Also, perhaps this is an opportunity to address handling single vs.
    multiple element parameters. That is, how to avoid things like both
    list.extend() and list.append() -- which one adds only a single
    element? If the language had a way to indicate whether a parameter
    should be treated as an atom vs. a collection, it would reduce a lot
    of ambiguous (within an object) and inconsistent (across objects)
    method names and the unending debate that seems to occur each time.

    Perhaps Python's later enhancements (decorators?) could make this more
    natural, or maybe a new construct would be required...

    BTW, I vote in favor of character case being semantically meaningful.
    I like the language informing me (and enforcing) semantic meaning
    through syntax (much like Python's indention). Ditto for bang-endings
    (ex. list.sorted!).

    Off the cuff, but only two cents....

    Zipher

    Comment

    • Greg Ewing (using news.cis.dfn.de)

      #77
      Re: A 'Python like' language

      Mark Hahn wrote:[color=blue][color=green]
      >> f = someobj.somemet h
      >> someotherobj.g = f
      >> someotherobj.g( )
      >>
      >> What does the "self" object inside the call to somemeth
      >> refer to then -- someobj, or someotherobj?[/color]
      >
      > It refers to someotherobj.[/color]

      You have a problem, then. This means passing functions around
      is fragile. If you store one in an attribute of an object, it
      mutates into something different when you get it back out
      again.

      --
      Greg Ewing, Computer Science Dept,
      University of Canterbury,
      Christchurch, New Zealand


      Comment

      • Mark Hahn

        #78
        Re: A 'Python like' language

        I need a better understanding of this. You are suggesting the self stay
        with a function like a closure of sorts?

        In my mind, anytime you say obj.func(), func is called on obj, no ifs ands
        or buts. How could it be otherwise? When would you want it otherwise?

        You say fragile. What breaks?


        "Greg Ewing (using news.cis.dfn.de )" <ieyf4fu02@snea kemail.com> wrote in
        message news:c4avp5$2g4 b0b$1@ID-169208.news.uni-berlin.de...[color=blue]
        > Mark Hahn wrote:[color=green][color=darkred]
        > >> f = someobj.somemet h
        > >> someotherobj.g = f
        > >> someotherobj.g( )
        > >>
        > >> What does the "self" object inside the call to somemeth
        > >> refer to then -- someobj, or someotherobj?[/color]
        > >
        > > It refers to someotherobj.[/color]
        >
        > You have a problem, then. This means passing functions around
        > is fragile. If you store one in an attribute of an object, it
        > mutates into something different when you get it back out
        > again.
        >
        > --
        > Greg Ewing, Computer Science Dept,
        > University of Canterbury,
        > Christchurch, New Zealand
        > http://www.cosc.canterbury.ac.nz/~greg
        >[/color]


        Comment

        • Mark Hahn

          #79
          Re: A 'Python like' language

          > Stackless-type systems tend to make this rather more convoluted than just
          making a C function call.

          I define a function call as:

          call_func(ist, self, func_sym, parm_cnt, lbl_val_arr, dyn_locals);

          This call is the same for interpreted Prothon or internal C code. It has
          the self object, the symbol telling the function name, and the passed
          parameters. ist is a struct passed around everywhere to keep interpreter
          state and keep things re-entrant. dyn_locals is used for dynamic local
          compatilility in C (which has never been used and may be pulled).
          lbl_val_arr is a C array (length of parm_cnt) of object pairs of labels (sym
          objects) and value objects. The labels allow one to do func(x=value).
          Usually, internally the labels are NULL. This structure supports
          func(*list, **dict) even internally.

          You may call this convoluted if you wish.


          "Greg Ewing (using news.cis.dfn.de )" <ieyf4fu02@snea kemail.com> wrote in
          message news:c4am81$2ha 0mj$1@ID-169208.news.uni-berlin.de...[color=blue]
          > Mark Hahn wrote:[color=green][color=darkred]
          > >>But I wonder what effect the lack of reference counting has
          > >>on cache-friendliness of the memory management system.[/color]
          > >
          > > I don't see how the lack of something could hurt the cache. Do you mean[/color][/color]
          the[color=blue][color=green]
          > > garbage colector?[/color]
          >
          > A running Python program creates and discards certain kinds
          > of objects (e.g. integers, tuples, stack frames) at a very
          > high rate. Due to reference counting, the fact that these
          > objects have been discarded is discovered very quickly, and
          > their memory released. Subsequent allocations are likely to
          > re-use the same memory, which is likely to be in cache.
          >
          > A pure mark-and-sweep system, on the other hand, tends to
          > keep on allocating fresh memory and letting the garbage
          > objects pile up until there is no more fresh memory, only
          > then pausing to reclaim the garbage. This is a very bad
          > access pattern for cache purposes.
          >
          > Back when the addition of a mark-and-sweep collector to
          > Python was being debated, this argument was put forward as
          > a reason why replacing reference counting with mark-and-sweep
          > wouldn't obviously be an improvement, and could make things
          > worse.
          >
          > Python currently has both reference counting *and* mark
          > and sweep, which sounds redundant, but the combination seems
          > to work very well.
          >[color=green]
          > > The interpreter supports C code calling Prothon code and vice versa.[/color]
          >
          > I don't doubt that it's possible, I was just wondering how
          > easy it is. Stackless-type systems tend to make this rather
          > more convoluted than just making a C function call. I'll take
          > a look at the code some time and find out.
          >
          > --
          > Greg Ewing, Computer Science Dept,
          > University of Canterbury,
          > Christchurch, New Zealand
          > http://www.cosc.canterbury.ac.nz/~greg
          >[/color]


          Comment

          • Mark Hahn

            #80
            Re: A 'Python like' language

            > --Take advantage of iterators early on for return values to avoid[color=blue]
            > things like having both dict.items() and dict.iteritems( ).[/color]

            Interestiong idea. Generators are fully supported so I could do this now.
            So gens would have to be allowed absolutely everywhere lists are allowed (is
            trhis possible?). Or are you thinking the user should type
            List(dict.items ()) ?
            [color=blue]
            > --Choose "{:}" syntax for empty dict creation to reserve "{}" for
            > sets. (Or: use "{}" for both, and do automatic "set-to-dict[/color]

            Also cool. Maybe <> for sets? Prothon doesn't support <> as != so it is
            free.
            [color=blue]
            > --Functions that return multiple, but unique, values should return a
            > set, not a list, to communicate same (ex: dict.keys(), dir(), etc.).[/color]

            Also cool.
            [color=blue]
            > --Dict should inherit from Set.[/color]

            Also cool (I feel like the credits of Holy Grail saying Also wik).
            [color=blue]
            > --No Dict.update(), since this is now identical with Set.__ior__()
            > (i.e. d1 |= d2).
            >[/color]

            Cool.

            .... snipped ...

            All cool.
            [color=blue]
            > --With prothon's "immutabili ty" bit and other considerations, does the
            > language need both tuples AND lists?[/color]

            I like this a lot. Tuples are already implemented internally as lists.

            .... more good stuff snipped ...
            [color=blue]
            > Off the cuff, but only two cents....[/color]

            More like a few dollars. This is really good stuff. Can I talk you into
            hanging out on the Prothon list now and then, at least until we get the core
            language sorted out?


            "Zipher" <average@moonma n.com> wrote in message
            news:30985729.0 403291959.2dafe 546@posting.goo gle.com...[color=blue]
            > [Mark Hann][color=green]
            > > Obviously Prothon is not Python compatible, so I have taken the liberty[/color][/color]
            of[color=blue][color=green]
            > > implementing many changes that have been imagined for the almost[/color][/color]
            mythical[color=blue][color=green]
            > > Python 3.0...[/color]
            >
            > Gee, my love of Python makes me feel a little guilty about looking at
            > another language, but Prothon does look appealing. Classes really do
            > start looking archaic... Would a threesome be out of the question?
            >
            > My Python3k suggestions for Prothon:
            >
            > --Take advantage of iterators early on for return values to avoid
            > things like having both dict.items() and dict.iteritems( ).
            > (Decorators add even larger possibilities for fresh syntax and other
            > considerations. )
            >
            > --Choose "{:}" syntax for empty dict creation to reserve "{}" for
            > sets. (Or: use "{}" for both, and do automatic "set-to-dict
            > promotion" upon encountering a (key, value) assignment.)
            >
            > --Functions that return multiple, but unique, values should return a
            > set, not a list, to communicate same (ex: dict.keys(), dir(), etc.).
            > (Consider iterator caveat above, however.)
            >
            > Such functions often have surprising uses for set operations anyway.
            > Consider, for example, using set operations on dir() to answer
            > questions like Which parent functions/variables get re-assigned in the
            > child class? or What new fns/vars does this child add?
            >
            > --Dict should inherit from Set.
            >
            > --No Dict.update(), since this is now identical with Set.__ior__()
            > (i.e. d1 |= d2).
            >
            > Could follow Python's behavior with regard to key collisions (a matter
            > of contentious debate if I remember), OR perhaps even better:
            >
            > --Dict object could contain optional "collision function attribute"
            > that is called to resolve values on key collisions.
            >
            > Consider, for example, an easy Bag(Dict) object with said attribute
            > assigned to "operator.a dd" for the union method(s). This would also
            > maintain the >10x speed factor (in Python anyway) of using underlying
            > C-implmentation rather that hand iteration through dicts.
            >
            > --With prothon's "immutabili ty" bit and other considerations, does the
            > language need both tuples AND lists?
            >
            > Also, perhaps this is an opportunity to address handling single vs.
            > multiple element parameters. That is, how to avoid things like both
            > list.extend() and list.append() -- which one adds only a single
            > element? If the language had a way to indicate whether a parameter
            > should be treated as an atom vs. a collection, it would reduce a lot
            > of ambiguous (within an object) and inconsistent (across objects)
            > method names and the unending debate that seems to occur each time.
            >
            > Perhaps Python's later enhancements (decorators?) could make this more
            > natural, or maybe a new construct would be required...
            >
            > BTW, I vote in favor of character case being semantically meaningful.
            > I like the language informing me (and enforcing) semantic meaning
            > through syntax (much like Python's indention). Ditto for bang-endings
            > (ex. list.sorted!).
            >
            > Off the cuff, but only two cents....
            >
            > Zipher[/color]


            Comment

            • Mark Hahn

              #81
              Re: A 'Python like' language

              If you were designing a new interpreter, would you consider reference
              counting an evil pain for C coders (as I did) and use some other GC, or do
              you think I made a mistake? Is there a compromise?


              "Greg Ewing (using news.cis.dfn.de )" <ieyf4fu02@snea kemail.com> wrote in
              message news:c4am81$2ha 0mj$1@ID-169208.news.uni-berlin.de...[color=blue]
              > Mark Hahn wrote:[color=green][color=darkred]
              > >>But I wonder what effect the lack of reference counting has
              > >>on cache-friendliness of the memory management system.[/color]
              > >
              > > I don't see how the lack of something could hurt the cache. Do you mean[/color][/color]
              the[color=blue][color=green]
              > > garbage colector?[/color]
              >
              > A running Python program creates and discards certain kinds
              > of objects (e.g. integers, tuples, stack frames) at a very
              > high rate. Due to reference counting, the fact that these
              > objects have been discarded is discovered very quickly, and
              > their memory released. Subsequent allocations are likely to
              > re-use the same memory, which is likely to be in cache.
              >
              > A pure mark-and-sweep system, on the other hand, tends to
              > keep on allocating fresh memory and letting the garbage
              > objects pile up until there is no more fresh memory, only
              > then pausing to reclaim the garbage. This is a very bad
              > access pattern for cache purposes.
              >
              > Back when the addition of a mark-and-sweep collector to
              > Python was being debated, this argument was put forward as
              > a reason why replacing reference counting with mark-and-sweep
              > wouldn't obviously be an improvement, and could make things
              > worse.
              >
              > Python currently has both reference counting *and* mark
              > and sweep, which sounds redundant, but the combination seems
              > to work very well.
              >[color=green]
              > > The interpreter supports C code calling Prothon code and vice versa.[/color]
              >
              > I don't doubt that it's possible, I was just wondering how
              > easy it is. Stackless-type systems tend to make this rather
              > more convoluted than just making a C function call. I'll take
              > a look at the code some time and find out.
              >
              > --
              > Greg Ewing, Computer Science Dept,
              > University of Canterbury,
              > Christchurch, New Zealand
              > http://www.cosc.canterbury.ac.nz/~greg
              >[/color]


              Comment

              • Paul Rubin

                #82
                Re: A 'Python like' language

                "Mark Hahn" <mark@prothon.o rg> writes:[color=blue]
                > I need a better understanding of this. You are suggesting the self stay
                > with a function like a closure of sorts?
                >
                > In my mind, anytime you say obj.func(), func is called on obj, no ifs ands
                > or buts. How could it be otherwise? When would you want it otherwise?[/color]

                Well, that's not how Python does it, though doing it some other way may
                not necessarily be "fragile".

                Comment

                • Paul Rubin

                  #83
                  Re: A 'Python like' language

                  "Mark Hahn" <mark@prothon.o rg> writes:[color=blue]
                  > If you were designing a new interpreter, would you consider
                  > reference counting an evil pain for C coders (as I did) and use some
                  > other GC, or do you think I made a mistake? Is there a compromise?[/color]

                  I think as long as you're using an interpreter, any performance that you
                  get back from improved cache behavior by reference counting will be lost
                  in the noise. If you're serious about performance you really should be
                  thinking about a native-code compiler. Only after that should you worry
                  much about the fine points of gc design.

                  Comment

                  • Jon Franz

                    #84
                    Re: A 'Python like' language

                    "Mark Hahn" <mark@prothon.o rg> wrote in message news:<6gS9c.581 50$cx5.19190@fe d1read04>...[color=blue]
                    > Speed tests on Prothon will be meaningless now. The code is chock full of
                    > debug stuff and is not optimized, either by humans or compiler. We mean it
                    > when we say pre-alpha.[/color]

                    Not necessarily - I'm not looking for raw performance, but rather
                    scalability. Many of the changes you've made in Prothon could either
                    improve or hurt scalability and CPU utilization in multithreaded
                    scenarios. Of course, as a pre-alpha, no full conclusions can be
                    drawn. But for example, what if Prothon scaled as well (or just
                    within an order of magnitude) as standard Python? Considering the
                    non-optimized nature of Prothon, that would bode very well, and could
                    start discussions in the Python community as to whether your sort of
                    APR based system with GC and multiple interpreters with native threads
                    is something to look at. After all, I do believe that the last time
                    removing the global interpreter lock was seriously pondered and tests
                    were done, the APR was not considered (possibly due to it not existing
                    in a usable state at the time), nor was moving to such a stackless
                    backend on the table at the same time.

                    Anyway, I'm busy with client work, and looking for more clients, so
                    I don't have the time to write any tests write now; perhaps by the
                    time I do (or someone else does) Prothon will be more mature.

                    ~Jon Franz
                    NeuroKode Labs, LLC

                    Comment

                    • Andrew Bennetts

                      #85
                      Re: A 'Python like' language

                      On Mon, Mar 29, 2004 at 10:46:42PM -0800, Mark Hahn wrote:[color=blue]
                      > I need a better understanding of this. You are suggesting the self stay
                      > with a function like a closure of sorts?
                      >
                      > In my mind, anytime you say obj.func(), func is called on obj, no ifs ands
                      > or buts. How could it be otherwise? When would you want it otherwise?[/color]

                      How is it possible to store a function from some object in another object
                      for later use, e.g. as a callback?

                      i.e. in Python syntax:

                      class C:
                      def __init__(self, callbackFunc):
                      self.callbackFu nc = callbackFunc

                      def fireCallback(se lf):
                      self.callbackFu nc()

                      c = C(someobj.metho d)

                      ...

                      c.fireCallback( )
                      [color=blue]
                      > You say fragile. What breaks?[/color]

                      The fragility I see is that storing a function in a variable doesn't modify
                      the function, but storing it as an attribute of an object does, i.e.

                      f = someobj.method
                      x = f
                      x()

                      behaves differently to:

                      otherobj.f = someobj.method
                      x = otherobj.f
                      x()

                      Python solves this by wrapping functions found in classes as (un)bound
                      methods (which keep track of the instance they were accessed from) -- but
                      functions found on *instances* (i.e. they are in the dict of the instance,
                      but not the class) are left alone. It works well :)

                      -Andrew.


                      Comment

                      • Gerrit

                        #86
                        Re: A 'Python like' language

                        Mark Hahn wrote:[color=blue][color=green]
                        > > --Take advantage of iterators early on for return values to avoid
                        > > things like having both dict.items() and dict.iteritems( ).[/color]
                        >
                        > Interestiong idea. Generators are fully supported so I could do this now.
                        > So gens would have to be allowed absolutely everywhere lists are allowed (is
                        > trhis possible?). Or are you thinking the user should type
                        > List(dict.items ()) ?[/color]

                        If it would be a list, yes, or maybe even dict.items().as list() or
                        similar. This because it is quite random for keys to be a list: it could
                        be a set. This has the advantage that one can do as in Ruby:
                        myobj.methods() - parent.methods( ). But I'm not sure whether parent.methods( )
                        is applicable to a prototype-based language.
                        [color=blue][color=green]
                        > > --Functions that return multiple, but unique, values should return a
                        > > set, not a list, to communicate same (ex: dict.keys(), dir(), etc.).[/color]
                        >
                        > Also cool.[/color]

                        It also applies to dict.items(). This could be either a generator or a
                        Set.
                        [color=blue][color=green]
                        > > --Dict should inherit from Set.[/color]
                        >
                        > Also cool (I feel like the credits of Holy Grail saying Also wik).[/color]

                        I have read (in c.l.py) that in Smalltalk, a Dict is a Set of Associates
                        or something similar. I don't know Smalltalk, but I like this idea of a
                        Set.

                        Gerrit.

                        --
                        Weather in Twenthe, Netherlands 30/03 13:25 UTC:
                        15.0°C wind 5.4 m/s E (57 m above NAP)
                        --
                        here will soon be Gerrit Holl's very own signature

                        Comment

                        • Gerrit

                          #87
                          Re: A 'Python like' language

                          Mark Hahn wrote:[color=blue]
                          > But everything in Prothon is subject to change until > 7/04.[/color]

                          Is that April the 7th or July the 4th?

                          Gerrit.

                          --
                          Weather in Twenthe, Netherlands 30/03 13:25 UTC:
                          15.0°C wind 5.4 m/s E (57 m above NAP)
                          --
                          here will soon be Gerrit Holl's very own signature

                          Comment

                          • Glenn Andreas

                            #88
                            Re: A 'Python like' language

                            In article <5J1ac.64492$cx 5.5801@fed1read 04>,
                            "Mark Hahn" <mark@prothon.o rg> wrote:
                            [color=blue][color=green]
                            > > So does "foo.bar = 5" add a "bar" slot to "foo" or does it change bar in[/color]
                            > the parent object?
                            >
                            > It took me great trouble to learn to use attribute instead of slot to keep
                            > Prothon in sync with Python. I even had to globally replace "slot" with
                            > "attr" in all my code a week ago, so I'll be replacing your use of slot with
                            > attribute.
                            >
                            > "foo.bar = 5" will always add an attribute bar to foo. You have to say
                            > "parent.bar = 5", or if foo is the current self object, you would say "^bar
                            > = 5". The caret(^) prefix reads as "super" and replaces the period prefix
                            > when you want atrribute lookup to start at the parent of self instead of at
                            > self. This was documented yesterday on the website.
                            >
                            > I realize that there is not currently any automatic way to change a value
                            > found by inheritance. I'm open to suggestions. None of the Prothon
                            > features will be cast in stone until 7/04 so make your suggestions known at
                            > Prothon mailing lists.[/color]

                            Self gets around this problem by the way it handles assignments as
                            method calls, so assigning to a specific attribute/slot/ivar of a
                            parent/superclass/prototype is handled like explicitly calling the
                            method via a resend or directed resend.

                            What makes this work is the fact that inheritance is handled by
                            "flagging" the slot of the object as something that it inherits from, by
                            having an "*" after the name, which results in inerhitance coming from
                            explicitly named "paths" rather than some implicit (and usually hidden)
                            "__super__" (for example). So "parent* = anotherObject", "super* =
                            anotherObject" and "proto* = anotherObject" all define "anotherObj ect"
                            as something this object inerhits from. As a result, it is easy to
                            explicitly say "parent.foo ", "super.foo" , "proto.foo" to narrow down
                            which thing to inherit from.

                            Perhaps a similar thing can work for Prothon? (i.e, explicit "named"
                            inheritance instead of implicit anonymous inheritence via "^")?

                            You could even use "^" for the default "super" (the non-directed
                            resend), and then something like "^(anotherParen t)" for the moral
                            equivalent of a directed resend.

                            Having named attributes/slots/ivars for inheritence also makes it easier
                            to handle dynamically changing multiple inheritence prototypes on the
                            fly (since you explicitly have a name for them)

                            Comment

                            • Terry Reedy

                              #89
                              Re: A 'Python like' language

                              What is 'this'? Who is 'you'? Where is the original suggestion? What did
                              who say what is fragile?

                              "Mark Hahn" <mark@prothon.o rg> wrote in message
                              news:1J8ac.6839 0$cx5.23284@fed 1read04...[color=blue]
                              > I need a better understanding of this. You are suggesting the self stay
                              > with a function like a closure of sorts?
                              >
                              > In my mind, anytime you say obj.func(), func is called on obj, no ifs[/color]
                              ands[color=blue]
                              > or buts. How could it be otherwise? When would you want it otherwise?
                              >
                              > You say fragile. What breaks?[/color]

                              Trying to read cryptic top-posted comments that require me to spend minutes
                              trying to find the most like referent in order to make any sense is too
                              much work for me. I won't do it. Good bye.

                              Terry J. Reedy




                              Comment

                              • Ype Kingma

                                #90
                                Re: A 'Python like' language

                                Mark,

                                you wrote:
                                [color=blue][color=green]
                                >> I do not yet know in detail how Prothon deals with module[/color]
                                > namespaces. These are important for larger scale programs,
                                > so I hope they got that right.
                                >
                                > I hope so too. We basicly have "module globals" exactly like Python. See
                                > "Module Globals and Real Globals" at http://prothon.org/description-3.htm.
                                > Please let me know if we got it wrong.[/color]

                                I'm not a language lawyer, so that took a quite while to sink in.
                                Nevertheless, it looks right.

                                Good luck,
                                Ype

                                Comment

                                Working...